Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled 'error' event on aborted request #36931

Closed
lpinca opened this issue Jan 14, 2021 · 6 comments
Closed

Unhandled 'error' event on aborted request #36931

lpinca opened this issue Jan 14, 2021 · 6 comments
Labels
confirmed-bug Issues with confirmed bugs. http Issues or PRs related to the http subsystem. linux Issues and PRs related to the Linux platform. macos Issues and PRs related to the macOS platform / OSX.

Comments

@lpinca
Copy link
Member

lpinca commented Jan 14, 2021

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

@lpinca lpinca added http Issues or PRs related to the http subsystem. macos Issues and PRs related to the macOS platform / OSX. labels Jan 14, 2021
@lpinca
Copy link
Member Author

lpinca commented Jan 14, 2021

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

cc: @nodejs/http

@ronag
Copy link
Member

ronag commented Jan 14, 2021

@lpinca
Copy link
Member Author

lpinca commented Jan 15, 2021

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

@lpinca lpinca added confirmed-bug Issues with confirmed bugs. linux Issues and PRs related to the Linux platform. labels Jan 15, 2021
@ronag
Copy link
Member

ronag commented Jan 16, 2021

Might have been solved with #36863

@ronag
Copy link
Member

ronag commented Jan 16, 2021

Needs a regression test either way.

@lpinca
Copy link
Member Author

lpinca commented Jan 16, 2021

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

ronag added a commit to nxtedition/node that referenced this issue Jan 16, 2021
ClientRequest could someone cause an unhandled error
from socket.

Fixes: nodejs#36931
@ronag ronag closed this as completed in fe43bd8 Feb 3, 2021
danielleadams pushed a commit that referenced this issue Feb 16, 2021
ClientRequest could someone cause an unhandled error
from socket.

Fixes: #36931

PR-URL: #36970
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. http Issues or PRs related to the http subsystem. linux Issues and PRs related to the Linux platform. macos Issues and PRs related to the macOS platform / OSX.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants