Skip to content

upload() will emit an error ECONNRESET after finish is called #704

Description

@sirisian

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions