FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

net: multiple listen() events fail silently by eduardbme · Pull Request #13149 · nodejs/node · GitHub

/ node Public

net: multiple listen() events fail silently - #13149

Closed
eduardbme wants to merge 1 commit into
nodejs:masterfrom
eduardbme:listenhasbeencalled
Closed

net: multiple listen() events fail silently#13149
eduardbme wants to merge 1 commit into
nodejs:masterfrom
eduardbme:listenhasbeencalled

Conversation

Copy link
Copy Markdown
Contributor
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows [commit guidelines]

Affected core subsystem(s)

net

Description of change

Problem: It's possible to run listen() on a net.Server that's already listening to a port.
The result is silent failure, with the side effect of changing the _connectionKey and or _pipeName.

Solution: emit error if listen method called more than once.
close() method should be called between listen() method calls.

Refs: #8294
Fixes: #6190
Fixes: #11685

Previous PR #8419

nodejs-github-bot added the net Issues and PRs related to the net subsystem. label May 22, 2017

Copy link
Copy Markdown
Contributor Author

hi there @jasnell @rvagg @addaleax @cjihrig @joyeecheung @evanlucas

@gibfahn have updated pr, please run CI
updated docs and moved away from accessors @bnoordhuis

gibfahn commented May 22, 2017

Copy link
Copy Markdown
Member

Comment thread doc/api/http.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There's no reason for the line break after *Note*: ...

*Note*: The `server.listen()` method...

Comment thread doc/api/http.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
during the first `listen()` call ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please avoid the use of you in docs :-)

Comment thread lib/net.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Rather than introducing a new state variable for tracking, just look for the existence of the _handle. If it is not undefined or null, the server is listening, otherwise it is not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What if the server._handle has been manually set to a non-listening wrap though?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Good point. But I think that the _ sign clearly says "okay, you know what you doing by accessing , sort of, private field. You are on your own way now".

jasnell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Good idea but the implementation and docs need a bit of work. Added a few comments. Thank you for working on this.

eduardbme force-pushed the listenhasbeencalled branch 4 times, most recently from b07d6f5 to fbe11dc Compare May 28, 2017 12:15

Copy link
Copy Markdown
Contributor Author

@jasnell updated pr

Comment thread lib/net.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The other thing I would recommend here is using the new internal/errors when introducing a new error.

jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label May 29, 2017
eduardbme force-pushed the listenhasbeencalled branch 2 times, most recently from 068bcbf to c566e77 Compare June 22, 2017 11:07

Copy link
Copy Markdown
Contributor Author

@jasnell moved away from EINVAL error, added new one inside errors called ERR_SERVER_ALREADY_LISTEN and updated tests.

cjihrig commented Jun 22, 2017

Copy link
Copy Markdown
Contributor

This is an interesting edge case. Would calling listen() twice be considered a programmer error? If so, we should throw, not emit an error. If we do stick with an emit(), should the PR return this for consistency with other returns in listen()?

Copy link
Copy Markdown
Member

@cjihrig I'd say it's a programmer error.

Copy link
Copy Markdown
Member

@cjihrig I think the theory is, if listen has already been called, whoever calls it is likely to have a error handler setup already and they should be notified. Although I think the second listen call should throw as well so the second caller can be notified ASAP

justsml left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Excellent work, very clean PR! 👍

Copy link
Copy Markdown
Member

@eduardbcom this needs a rebase and as far as I see it the emit should be changed to throwing right away.

BridgeAR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

One comment, otherwise LGTM

eduardbme force-pushed the listenhasbeencalled branch from c566e77 to eadf97a Compare August 29, 2017 20:27

Copy link
Copy Markdown
Contributor Author

@BridgeAR done

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Nit: typo (can be fixed while landing though)

Copy link
Copy Markdown
Member

Copy link
Copy Markdown
Member

@gibfahn @cjihrig @joyeecheung @jasnell you might want to have another look as the emit now changed to a throw instead.

jasnell commented Aug 30, 2017

Copy link
Copy Markdown
Member

Still LGTM but I'd like to get more @nodejs/ctc reviews

mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

Comment thread doc/api/http.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Drop the word "method" after server.close() in this sentence.

Comment thread doc/api/http.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

would be -> will be

Comment thread doc/api/http.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Same comments apply to this paragraph and the one below.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Style nit, but could you move this to the previous line. It saves a level of indentation.

Problem:
It's possible to run listen()
  on a net.Server that's already listening to a port.
The result is silent failure,
  with the side effect of changing the connectionKey and or pipeName.

Solution:
  throw an error if listen method called more than once.
  close() method should be called between listen() method calls.

Refs: nodejs#8294
Fixes: nodejs#6190
Fixes: nodejs#11685

Copy link
Copy Markdown
Contributor Author

Thank you folks for your comments. Updated

Copy link
Copy Markdown
Member

joyeecheung left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM if CI is happy

mcollina commented Sep 4, 2017

Copy link
Copy Markdown
Member

CI failures are unrelated, this can land.

mcollina commented Sep 4, 2017

Copy link
Copy Markdown
Member

Landed as b24e269.

mcollina closed this Sep 4, 2017

mcollina commented Sep 4, 2017

Copy link
Copy Markdown
Member

Thanks @eduardbcom for your contribution!

mcollina pushed a commit that referenced this pull request Sep 4, 2017
Problem:
It's possible to run listen()
  on a net.Server that's already listening to a port.
The result is silent failure,
  with the side effect of changing the connectionKey and or pipeName.

Solution:
  throw an error if listen method called more than once.
  close() method should be called between listen() method calls.

Refs: #8294
Fixes: #6190
Fixes: #11685
PR-URL: #13149
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
addaleax pushed a commit to addaleax/ayo that referenced this pull request Sep 5, 2017
Problem:
It's possible to run listen()
  on a net.Server that's already listening to a port.
The result is silent failure,
  with the side effect of changing the connectionKey and or pipeName.

Solution:
  throw an error if listen method called more than once.
  close() method should be called between listen() method calls.

Refs: nodejs/node#8294
Fixes: nodejs/node#6190
Fixes: nodejs/node#11685
PR-URL: nodejs/node#13149
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

net Issues and PRs related to the net subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document that you can only listen on an already closed socket net: multiple listen() events fail silently

9 participants


Back | FazBrowse Home | New Git URL