-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
net: close connection if no 'connection' listener #32516
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Ensure that a net.Server without 'connection' event listeners closes | ||
| // incoming connections rather than accepting, then forgetting about them. | ||
|
|
||
| 'use strict'; | ||
| const common = require('../common'); | ||
| const net = require('net'); | ||
|
|
||
| net.createServer(common.mustCall()).listen(function() { | ||
| const server = this; | ||
| const { address: host, port } = server.address(); | ||
| net.connect(port, host).once('end', () => server.close()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably be
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bnoordhuis: I think if you change this to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ronag At least locally for me, that doesn’t work 😕
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll take a look this week.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @addaleax This seems to be related to a bug on the tcp handle. _handle.readStart is called but _handle.onread is never invoked, in this case I guess it should be an error such as ECONNRESET.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably a bug that also affects the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ronag I feel like we had a conversation about this recently, assuming that we’re talking about the client handle here – namely that
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I thought this wasn't necessary. That's at least what I got from the conversation and that the handle should detect ungraceful disconnection?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a feeling this might be expensive for all incoming connections. Instead, you can check the return value of
emit: https://nodejs.org/api/events.html#events_emitter_emit_eventname_args.