-
Notifications
You must be signed in to change notification settings - Fork 372
Open
Description
I was doing asynchronous code in the finish handler for an upload, and I noticed that the error handler is not unregistered after finish is called. At least in node v20.15.1 this can report ECONNRESET when the socket closes.
This required that I add the following logic to my upload which is kind of annoying. Even if I'm not doing any asynchronous code the call will still output an error to my logs which is not ideal.
let ignoreErrors = false;
let writeStream = storageClient.upload({
container,
remote,
headers: {
'Access-Control-Allow-Origin': '*'
}
}).on('error', error => {
if (!ignoreErrors) {
console.log(`write stream error: ${JSON.stringify(error)}`);
reject();
}
}).on('finish', () => {
ignoreErrors = true;
console.log('finished');
// Asynchronous code before I resolve();
});"write stream error: {\"message\":\"socket hang up\",\"stack\":\"Error: socket hang up\\n at TLSSocket.socketOnEnd (node:_http_client:524:23)\\n at TLSSocket.emit (node:events:531:35)\\n at endReadableNT (node:internal/streams/readable:1696:12)\\n at process.processTicksAndRejections (node:internal/process/task_queues:82:21)\",\"code\":\"ECONNRESET\"}"}
I'd recommend disconnecting the error handler as soon as the finish is called as such errors aren't useful.
msimomni-lgtm
Metadata
Metadata
Assignees
Labels
No labels