sindresorhus / got

šŸŒ Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

Socket hang-up no retry? #1671

Closed Sytten closed 3 years ago

Sytten commented 3 years ago

Describe the bug

Actual behavior

I use got with a retry limit of 8, so I expect that all requests will got through eventually. But it seems like got doesn't retry on socket hang-up. I got the following error:

RequestError: socket hang up
    at ClientRequest.<anonymous> (/app/node_modules/got/dist/source/core/index.js:953:111)
    at Object.onceWrapper (events.js:422:26)
    at ClientRequest.emit (events.js:327:22)
    at ClientRequest.origin.emit (/app/node_modules/@szmarczak/http-timer/dist/source/index.js:39:20)
    at TLSSocket.socketOnEnd (_http_client.js:493:9)
    at TLSSocket.emit (events.js:327:22)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at connResetException (internal/errors.js:607:14)
    at TLSSocket.socketOnEnd (_http_client.js:493:23)
    at TLSSocket.emit (events.js:327:22)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)

Expected behavior

It should retry on socket hang-up, unfortunately I don't have all the details of the error since I only log the message and the stack trace.

Code to reproduce

I will try to create a repro, but unsure when the error occurs. Is it the server that closes the connection?

Checklist

szmarczak commented 3 years ago

Yes, ECONNRESET errors cause a retry. If all the 8 retries failed, it throws. I'll reopen if you can reproduce the issue.