Got: response under error causing unhandled promise rejection

Created on 8 Jun 2020  路  10Comments  路  Source: sindresorhus/got

Describe the bug

  • Node.js version: v13.14.0
  • OS & version: Tested over Linux and Mac

Actual behavior

When a request is performed by got and it throws an error, got returns the error properly.

However, since the original request response is still a thing living at error.response and it's a stream, errors can still happen (e.g., an HTTP parser error), creating scenarios where the underlying request errors throw without a handler associated.

Code to reproduce

Expected behavior

First, not sure if this is an edge case got should to handle.

In my particular case, since got throws an error at the first level, that all that I need to know and the underlying error can be skipped.

I tried to skip it using hooks or cancelling the internal response without success.

Most helpful comment

Getting the same error using node 14.10.1, 14.10.0, 14.14.0 and various version of got starting with 11.5.1, 11.6.2, 11.7. Also using node Pipeline. I cannot get it to reproduce the error every time and normally happens with larger data transfers.

All 10 comments

Yes, we also noticed such "UnhandledRejections" since some version of got (not sure from which one). Looks not right.

I can't catch the error when the status code is 400 with version 11.3, but it's ok on version 10.x.

Same thing happening to me. It's happening when the server aborts the pending request.

It seems Transfer-Encoding: chunked, as response header, is related somehow. But this is only a guess.

Added another way to reproduce the error:

const got = require('got')
const pReflect = require('p-reflect')

const result = await pReflect(got('https://gitlab.com/edpratti'))

console.log(result)

In this case, under 5xx, an unhandled promise reaches the process execution

Simplest repro:

(async () => {
    try {
        await got('https://gitlab.com/users/sign_in', {retry: 1});
    } catch (error) {
        console.log('CAUGHT', error);
    }
})();

Hey, I'm seeing this is anything newer than 11.2.0 ReadError: The server aborted the pending request

Released [email protected].

Having this issue while downloading bigger files on windows node 14 with got 11.7

ReadError: The server aborted pending request

after some time.
The Application is packed with pkg

Smaller files work. Seems there is a timeout?

      await pipelinePromised(
        got.stream(fromUrl),
        fs.createWriteStream(targetFile)
      );

Getting the same error using node 14.10.1, 14.10.0, 14.14.0 and various version of got starting with 11.5.1, 11.6.2, 11.7. Also using node Pipeline. I cannot get it to reproduce the error every time and normally happens with larger data transfers.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lukechu10 picture lukechu10  路  3Comments

carvallegro picture carvallegro  路  4Comments

jamestalmage picture jamestalmage  路  3Comments

tkoelpin picture tkoelpin  路  3Comments

sindresorhus picture sindresorhus  路  3Comments