Got: Got doesn't retry if get "The server aborted the pending request" error

Created on 10 Jun 2020  Â·  6Comments  Â·  Source: sindresorhus/got

Describe the bug

  • Node.js version: v12.17.0
  • OS & version: Windows 10 x64 2004

Actual behavior

Make request to the server
The server aborted the pending request
got returned error
error have code "undefined"

ReadError: The server aborted the pending request
    at IncomingMessage.<anonymous> (T:\test\node_modules\got\dist\source\core\index.js:675:31)
    at Object.onceWrapper (events.js:421:28)
    at IncomingMessage.emit (events.js:315:20)
    at IncomingMessage.origin.emit (T:\test\node_modules\@szmarczak\http-timer\dist\source\index.js:39:20)
    at TLSSocket.socketCloseListener (_http_client.js:383:11)
    at TLSSocket.emit (events.js:327:22)
    at net.js:674:12
    at TCP.done (_tls_wrap.js:566:7) {
  code: undefined,
  timings: {
    start: 1591341068984,
    socket: 1591341068984,
    lookup: 1591341068986,
    connect: 1591341069136,
    secureConnect: 1591341069308,
    upload: 1591341069308,
    response: 1591341069831,
    end: 1591341082428,
    error: undefined,
    abort: undefined,
    phases: {
      wait: 0,
      dns: 2,
      tcp: 150,
      tls: 172,
      request: 0,
      firstByte: 523,
      download: 12597,
      total: 13444
    }
  },
  bufferedData: <Buffer 8d 0a 64 42 d2 1b 4c 28 8f 1d 14 24 40 52 56 e2 09 ef fa 4c f2 90 e0 cd e8 dd ef 2e e1 d1 4a bf a7 12 6d 92 9c 94 61 7e 5b f8 06 2b 15 3f dd 38 eb b7 ... 1251646 more bytes>
}

Expected behavior

Make request to the server
The server aborted the pending request
got will retry request if retry option set
got returned response or error

Code to reproduce

const got = require('got');
(async () => {
    try{
        let r = await got('http://httpbin.org/anything?test=1', { retry: 5 });
        console.log(r);
    }
    catch(e){
        console.log(e);
    }
})();

Checklist

  • [x] I have read the documentation.
  • [x] I have tried my code with the latest version of Node.js and Got.
bug regression ✭ help wanted ✭

Most helpful comment

Same issue here. I got:

UnhandledPromiseRejectionWarning: ReadError: The server aborted the pending request

What really bothers me (most) is that I can't catch it with a try...catch....

All 6 comments

up, same issue

(node:28276) UnhandledPromiseRejectionWarning: ReadError: The server aborted the pending request at IncomingMessage. (/storage/emulated/0/Download/Project/spotify/node_modules/got/dist/source/core/index.js:684:31)
at Object.onceWrapper (events.js:421:28)
at IncomingMessage.emit (events.js:315:20)
at IncomingMessage.origin.emit (/storage/emulated/0/Download/Project/spotify/node_modules/@szmarczak/http-timer/dist/source/index.js:39:20) at TLSSocket.socketCloseListener (_http_client.js:420:11) at TLSSocket.emit (events.js:327:22) at net.js:671:12 at TCP.done (_tls_wrap.js:561:7) (Use node --trace-warnings ... to show where the warning was created)

started getting this error aswell

(node:14676) UnhandledPromiseRejectionWarning: ReadError: The server aborted the pending request
at IncomingMessage. (\node_modules\got\dist\source\core\index.js:684:31)
at Object.onceWrapper (events.js:421:28)
at IncomingMessage.emit (events.js:315:20)
at IncomingMessage.origin.emit (\node_modules\@szmarczak\http-timer\dist\source\index.js:39:20)
at TLSSocket.socketCloseListener (_http_client.js:422:11)
at TLSSocket.emit (events.js:327:22)
at net.js:670:12
at TCP.done (_tls_wrap.js:562:7)
(Use node --trace-warnings ... to show where the warning was created)

The fix is just to add a code property here:

https://github.com/sindresorhus/got/blob/56df87671c741251a657fd57f60857ed9927f76b/source/core/index.ts#L1079-L1084

This used to be ECONNRESET

Same issue here. I got:

UnhandledPromiseRejectionWarning: ReadError: The server aborted the pending request

What really bothers me (most) is that I can't catch it with a try...catch....

@dannycreations @zedd3v @SukkaW Fixed. See #1308

@szmarczak Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sindresorhus picture sindresorhus  Â·  3Comments

joolfe picture joolfe  Â·  3Comments

lukechu10 picture lukechu10  Â·  3Comments

lukehorvat picture lukehorvat  Â·  3Comments

framerate picture framerate  Â·  4Comments