Skip to content

Unhandled 'error' event on aborted request #36931

Description

@lpinca
  • Version: v8.17.0, v10.23.1, v12.20.1, v14.15.4, v15.5.1
  • Platform: Darwin imac.local 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec 2 20:39:59 PST 2020; root:xnu-7195.60.75~1/RELEASE_X86_64 x86_64
  • Subsystem: http

What steps will reproduce the bug?

$ cat test.js 
const http = require('http');

const req = http.get('http://[2604:1380:45f1:3f00::1]:4002');

req.on('error', console.error);
req.abort();
$ node test.js 
node:events:353
      throw er; // Unhandled 'error' event
      ^

Error: connect EHOSTUNREACH 2604:1380:45f1:3f00::1:4002 - Local (:::49474)
    at internalConnect (node:net:910:16)
    at defaultTriggerAsyncIdScope (node:internal/async_hooks:430:12)
    at node:net:1001:9
    at processTicksAndRejections (node:internal/process/task_queues:75:11)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:188:8)
    at emitErrorCloseNT (node:internal/streams/destroy:153:3)
    at processTicksAndRejections (node:internal/process/task_queues:80:21) {
  errno: -65,
  code: 'EHOSTUNREACH',
  syscall: 'connect',
  address: '2604:1380:45f1:3f00::1',
  port: 4002
}

How often does it reproduce? Is there a required condition?

Always. No required condition.

What is the expected behavior?

The error is handled by the 'error' event listener.

What do you see instead?

The error is not handled.

Additional information

If req.abort() is removed the error is correctly handled.

Activity

  1. added
    httpIssues and PRs related to the http subsystem.
    macosIssues and PRs related to the macOS platform.
    on Jan 14, 2021
  2. lpinca commented on Jan 14, 2021

    @lpinca
    MemberAuthor

    onSocketNT() is called before the 'error' event is emitted but there are no listeners. The listener is added by tickOnSocket().

    cc: @nodejs/http

  3. lpinca commented on Jan 15, 2021

    @lpinca
    MemberAuthor

    @ronag it's not that. The error is emitted after onSocketNT() is called. Adding an 'error' listener here https://github.com/nodejs/node/blob/v15.5.1/lib/_http_client.js#L814-L819 would be sufficient.

  4. added
    confirmed-bugIssues and PRs for confirmed bugs.
    linuxIssues and PRs related to the Linux platform.
    on Jan 15, 2021
  5. ronag commented on Jan 16, 2021

    @ronag
    Member

    Might have been solved with #36863

  6. ronag commented on Jan 16, 2021

    @ronag
    Member

    Needs a regression test either way.

  7. lpinca commented on Jan 16, 2021

    @lpinca
    MemberAuthor

    #36863 fixes this only if no agent is used. It does not fix the example in the issue description.

  8. added a commit that references this issue on Jan 16, 2021
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

    confirmed-bugIssues and PRs for confirmed bugs.httpIssues and PRs related to the http subsystem.linuxIssues and PRs related to the Linux platform.macosIssues and PRs related to the macOS platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions