-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Random port: 0 doesn’t work on Node 0.12.0 #9194
Comments
Can you tell me your OS? I'm not seeing this issue on Linux:
|
Sure, I'm running OSX 10.10.1. I haven't tested on Linux. Did you happen to try the test that's in the link I pasted? I'd be curious to see if it passes on Linux. |
I dont have any problems in my Mac.
|
Without a stack trace, it's more difficult to say, but I'm guessing that the portscanner module used by grunt-contrib-connect is doing something like this: require('net').createConnection({port: 0}); |
I don't think this is a bug in node. This is a bug in grunt-contrib-connect and its use of node-portscanner by passing the For clarity here is the related stack trace.
|
I don't know if I'm wrong about this or not but pointed out to me in the above issue, this is a regression from node 0.10. In node 0.10 connecting to port 0 or 65536 emits an EADDRNOTAVAIL error. Connecting to any port in the range that doesn't have a server bound to it emits an ECONNREFUSED error. Those match the RangeError but the the error has become synchronous and is creating this issue for portscanner and grunt-contrib-connect as portscanner was written expecting asynchronous errors. Just figured I'd add this to the conversation having poked around a bit further. |
I agree with @mzgoddard's astute observation. Right or wrong, this was not causing an issue in node 10.x. This appears to be a regression that is affecting multiple modules. I don't use the grunt modules but I am experiencing this issue with the node-spdy module. |
Some background on this: The error message you are seeing was added to 0.11.8 in d80d131 to prevent non-int ports. However, it was possible that a DNS lookup would occur before validating the port, resulting in an asynchronously thrown (not emitted) exception. So, I moved the check to The real question is whether or not calling |
I'm not sure if this is even related, but it seems like BSD-based operating systems treat port 0 as a "special" port, which may have something to do with the fact that this issue appears to only be affecting OSX and FreeBSD. Found this on the web: "The designers of the original Berkeley UNIX "Sockets" interface, upon which much of the technology and practice we use today is based, set aside the specification of "port 0" to be used as a sort of "wild card" port. When programming the Sockets interface, the provision of a zero value is generally taken to mean "let the system choose one for me". Programmers who specify "port 0" know that it is an invalid port. They are asking the operating system to pick and assign whatever non-zero port is available and appropriate for their purpose." Also, wikipedia (not that it's authoritative) lists 0 as a valid port: "The port numbers in the range from 0 to 1023 are the well-known ports or system ports." |
@trevnorris @tjfontaine @misterdjules thoughts? I don't see real harm in supporting port 0, even though I don't find it particularly useful on the client. |
@cjihrig We should support port 0. |
It is standard behavior for most network system that binding to port 0 will give you a "random" available port. This has been the traditional functionality in node.js and it seems like a serious regression that it is no longer supported. |
The added validation allows non-negative numbers and numeric strings. All other values result in a thrown exception. Fixes: #9194 PR-URL: #9268 Reviewed-By: Julien Gilli <julien.gilli@joyent.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: James M Snell <jasnell@users.noreply.github.com>
Closed in 1a2a4da |
When can we expect a release that includes this ? Thanks 😍 |
@quentindemetz The fix for this issue will be released in node v0.12.1. node v0.12.1 will be released when all issues and PRs in the the 0.12.1 milestone are closed. |
gruntjs/grunt-contrib-connect#126
See the above issue link in the gruntjs project for details. This was apparently an issue in node v0.11.0, but no one filed it in the node project because v0.11.x was the experimental branch. This issue is now appearing in node v0.12.0.
To be clear, this issue doesn't appear to be an issue with gruntjs because I am seeing it in a completely different context in a project using the node-spdy library, which doesn't use gruntjs at all.
The text was updated successfully, but these errors were encountered: