sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.24k stars 934 forks source link

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

Closed seiya-git closed 4 years ago

seiya-git commented 4 years ago

Describe the bug

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

dannycreations commented 4 years ago

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)

zedd3v commented 4 years ago

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)

szmarczak commented 4 years ago

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

SukkaW commented 4 years ago

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....

szmarczak commented 4 years ago

@dannycreations @zedd3v @SukkaW Fixed. See #1308

SukkaW commented 4 years ago

@szmarczak Thanks!