-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
onUploadFinish error throw not being returned to client #380
Comments
Hi, that is very surprising considering I have this end-to-end test: tus-node-server/packages/server/test/Server.test.ts Lines 361 to 377 in d95dc19
I'll try to reproduce |
I forget env details: node: v16.15.1 lsb_release -a |
Running 'yarn test' resulted in: @tus/server:test: ✔ should call onUploadFinish and return its error to the client |
I also ran the following: `import * as fs from 'node:fs'; const path = 'const path = './example.doc';'; const stats = fs.statSync(path); fetch('http://127.0.0.1:1080/uploads/', { which resulted in:
|
It seems the following pattern may be part of the root cause. line 208 of server.ts file: the hanlder.send writes the file the store and calls: const writtenRes = this.write(res, 201, {Location: url, ...headers}) the write method, line 25, from the basehandler.ts:
writing the file to the store returns the entire http response to the tus client. the server runs the onUploadFinish and tries to send the error 500, but at that point i think the client has disco'd the connection already. you should be able to see this if you add something like the following to BaseHandler.js file in your node_modules dist: console.log('basehandler->write', status, headers, body); you'll see the server writing both responses to the wire. Wireshark / tcpdump should confirm the tus client disconnecting after the first 201 response. thoughts ? |
Thanks for looking into this. I'm currently on holiday until 22 February. I'll look into this when I'm back. |
Alright I looked into it. The behaviour is in fact correctly working but tus-js-client will only show it failed if you return HTTP 400. Started a discussion here: tus/tus-js-client#557 |
Hi,
Not sure if I'm missing something. I tried a simple server:
`'use strict'
import {Server} from '@tus/server';
import {FileStore} from '@tus/file-store';
const host = '127.0.0.1'
const port = 1080
const server = new Server({
path: '/uploads',
datastore: new FileStore({directory: './uploads'}),
async onUploadFinish(req, res, upload) {
throw {body: 'no', status_code: 500};
return res;
}
})
server.listen({host, port})`
And when I try with a simple tus client:
`'use strict'
import * as fs from 'node:fs';
import * as tus from 'tus-js-client';
const path = './example.doc';
const file = fs.createReadStream(path);
const options = {
endpoint: 'http://127.0.0.1:1080/uploads/',
metadata: {
filename: 'example.doc',
filetype: 'application/msword',
description: 'scooby doobie doo'
},
onError (error) {
console.error('An error occurred:')
console.error(error)
process.exitCode = 1
},
onProgress (bytesUploaded, bytesTotal) {
const percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(2)
console.log(bytesUploaded, bytesTotal,
${percentage}%
)},
onSuccess () {
console.log('Upload finished:', upload.url)
},
};
const upload = new tus.Upload(file, options);
upload.start();`
The upload completes without error.
node ./tus-client.js
0 3690496 0.00%
65536 3690496 1.78%
3690496 3690496 100.00%
Upload finished: http://127.0.0.1:1080/uploads/b21c2577eee60411d30b9edc01d7b4ff
Any help would be appreciated!
thanks
The text was updated successfully, but these errors were encountered: