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

net: support passing null to listen() #14221

Merged
merged 1 commit into from
Sep 22, 2017
Merged

net: support passing null to listen() #14221

merged 1 commit into from
Sep 22, 2017

Conversation

cjihrig
Copy link
Contributor

@cjihrig cjihrig commented Jul 13, 2017

This commit fixes a regression around the handling of null as the port passed to Server#listen(). With this commit, null, undefined, and 0 have the same behavior, which was the case in Node 4.

Fixes: #14205

R= @sam-github @evanlucas

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

net

@nodejs-github-bot nodejs-github-bot added the net Issues and PRs related to the net subsystem. label Jul 13, 2017
@@ -42,6 +42,7 @@ const listenOnPort = [
listen('0', common.mustCall(close));
listen(0, common.mustCall(close));
listen(undefined, common.mustCall(close));
listen(null, common.mustCall(close));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It may not be obvious, but because of the loop, this tests both cases that were removed below.

Copy link
Contributor

@refack refack left a comment

Choose a reason for hiding this comment

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

What's the semverity?

lib/net.js Outdated
@@ -1446,7 +1446,8 @@ Server.prototype.listen = function() {
// or (options[, cb]) where options.port is explicitly set as undefined,
// bind to an arbitrary unused port
if (args.length === 0 || typeof args[0] === 'function' ||
(typeof options.port === 'undefined' && 'port' in options)) {
((options.port === undefined || options.port === null) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Tiny nit: could you swap the && clauses (for readability)

@refack
Copy link
Contributor

refack commented Jul 13, 2017

Regarding semverity — IMHO should be patch
Ref: #14205 (comment)

@sam-github
Copy link
Contributor

I tested this against test/parallel/test-net-listen-port-option.js from #14234 (6.x), and it has a different behaviour. 4.x and 6.x allow listen(null), but do not allow listen({port: null}), but with this change, that latter behaviour becomes allowed.

I am out of time for the day, but I also suspect that the true/false behaviour may be different. 8.x doesn't support true/false as aliases for 1/0 in listen(true or false) (this is good), but I think it might in listen({port: true or false}). I think accepting true or false as meaning 1 or 0 was a bug that should be (and maybe partially is?) in 8.x or as soon as is possible given the semver-majorness of the change. This doesn't look related to this PR.

Copy link
Contributor

@sam-github sam-github left a comment

Choose a reason for hiding this comment

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

I confirmed, this introduces null being allowed not only as an argument to listen(), but also as an option to listen, making it incompatible with 6.x and 4.x:

core/node (pr/14221 $% u=) % ./out/Release/node -pe 'var s = require("http").createServer(function(){}).listen(undefined, function(){}).unref(); s.address()'                 
{ address: '::', family: 'IPv6', port: 32983 }
core/node (pr/14221 $% u=) % nvm i 6
v6.11.1 is already installed.
Now using node v6.11.1 (npm v3.10.10)
core/node (pr/14221 $% u=) % node -v && node -pe 'var s = require("http").createServer(function(){}).listen(undefined, function(){}).unref(); s.address()'                    
v6.11.1
internal/net.js:17
    throw new RangeError('"port" argument must be >= 0 and < 65536');

@BridgeAR
Copy link
Member

Ping @cjihrig

@cjihrig
Copy link
Contributor Author

cjihrig commented Sep 10, 2017

I'm OK with introducing listen(null) and listen({port: null}) both working because it's backward compatible. The option parsing for listen() is already overly complicated and convoluted. I don't really want to monkey with it any more than is necessary. So, if this change is going to be rejected, I'd rather close the PR.

@cjihrig
Copy link
Contributor Author

cjihrig commented Sep 20, 2017

Any takers on what to do with this one? I'd like to either land it or close it.

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

I am somewhat against this because I think it is better to have less implicit behavior. It is just less error prone. I do not have such a strong opinion about it to block it though.

lib/net.js Outdated
@@ -1446,7 +1446,8 @@ Server.prototype.listen = function() {
// or (options[, cb]) where options.port is explicitly set as undefined,
Copy link
Member

Choose a reason for hiding this comment

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

The comment should reflect the new behavior.

Copy link
Contributor

@sam-github sam-github left a comment

Choose a reason for hiding this comment

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

will leave review as a comment

Copy link
Contributor

@sam-github sam-github left a comment

Choose a reason for hiding this comment

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

Sorry for the churn, re #14221 (comment)

I agree its consistent to have the argument value to mean the same thing whether it is provided as a positional argument, or the value of an option property.

LGTM

@cjihrig
Copy link
Contributor Author

cjihrig commented Sep 22, 2017

@gibfahn is there a problem with the lint job on CI? Linting is failing for me, despite passing locally. See https://ci.nodejs.org/job/node-test-linter/11939/console.

It looks like it's happening on other PRs too. See https://ci.nodejs.org/job/node-test-linter/11936/console (although I haven't confirmed if that passes linting locally).

EDIT: I confirmed with @mcollina that the second case does have linting errors. I'm still not sure about the linting for this PR though.

@gibfahn
Copy link
Member

gibfahn commented Sep 22, 2017

@cjihrig probably #15441 getting landed without CI. Let me check.

Run on master to confirm: https://ci.nodejs.org/job/node-test-linter/11941/console

EDIT: Actually that was green.

Also weird that it's now taking me 70s to rerun make lint on my machine, I'm sure it was substantially less before.

This commit fixes a regression around the handling of null
as the port passed to Server#listen(). With this commit,
null, undefined, and 0 have the same behavior, which was the
case in Node 4.

Fixes: nodejs#14205
PR-URL: nodejs#14221
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@cjihrig
Copy link
Contributor Author

cjihrig commented Sep 22, 2017

Here is a CI run: https://ci.nodejs.org/job/node-test-pull-request/10196/

There were no related failures, but the linter failed. It seems like @gibfahn got that straightened out because here is a CI run with no code changes where the linter passes: https://ci.nodejs.org/job/node-test-pull-request/10204/. Thanks @gibfahn

Landing this.

@cjihrig cjihrig merged commit 20259f9 into nodejs:master Sep 22, 2017
@cjihrig cjihrig deleted the 14205 branch September 22, 2017 16:47
@gibfahn
Copy link
Member

gibfahn commented Sep 22, 2017

There were no related failures, but the linter failed. It seems like @gibfahn got that straightened out because here is a CI run with no code changes where the linter passes

nodejs/build#893

addaleax pushed a commit to addaleax/ayo that referenced this pull request Sep 23, 2017
This commit fixes a regression around the handling of null
as the port passed to Server#listen(). With this commit,
null, undefined, and 0 have the same behavior, which was the
case in Node 4.

Fixes: nodejs/node#14205
PR-URL: nodejs/node#14221
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
jasnell pushed a commit that referenced this pull request Sep 25, 2017
This commit fixes a regression around the handling of null
as the port passed to Server#listen(). With this commit,
null, undefined, and 0 have the same behavior, which was the
case in Node 4.

Fixes: #14205
PR-URL: #14221
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins
Copy link
Contributor

Support for passing undefined was added to v6.x in caeee38, but we still don't have support for null

@cjihrig would you be willing to backport this?

watson added a commit to watson/apm-agent-nodejs that referenced this pull request Dec 5, 2018
Early versions of Node.js 8 had a regression around the handling of
`null` as the port passed to `Server#listen()`. For details see:

nodejs/node#14221
watson added a commit to elastic/apm-agent-nodejs that referenced this pull request Dec 6, 2018
Early versions of Node.js 8 had a regression around the handling of
`null` as the port passed to `Server#listen()`. For details see:

nodejs/node#14221
watson added a commit to elastic/apm-agent-nodejs that referenced this pull request Dec 6, 2018
Early versions of Node.js 8 had a regression around the handling of
`null` as the port passed to `Server#listen()`. For details see:

nodejs/node#14221
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

undefined port should trigger a RangeError when launching a server