You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If server.listen is used with a host, then get-port only returns the correct result if the samehost value is provided.
// Some other project running on your machine:server.listen(3000,'localhost',cb);
This works, because we put in the host localhost, matching above:
// Your project:awaitgetPort({port: 3000,host: 'localhost'})// => Random port that is not bound to localhost, good!
However, when you don't know what host was used in the other project, or what host will be used in yours, you could be in trouble:
// Some other project running on your machine:server.listen(3000,'localhost',cb);// Your project does one of these:awaitgetPort({port: 3000})// => 3000...awaitgetPort({port: 3000,host: '0.0.0.0'})// => 3000...awaitgetPort({port: 3000,host: '127.0.0.1'})// => 3000...awaitgetPort({port: 3000,host: '::'})// => 3000...
If that 3000 port is then used later in your code with localhost, it will fail.
This might be a deficiency or feature in libev, or I'm not understanding how port binding works when the host is provided.
Workaround 1
Always use the same host when creating your server as used when running get-port. I'm finding that to not always be feasible.
Workaround 2
Math.max(awaitgetPort({port: 3000,host: 'localhost'}),awaitgetPort({port: 3000,host: '0.0.0.0'}));// => Will always be a random port, even if 3000 is available, // because `lockedPorts` ignores the `host`, so one of the two // getPort calls will think 3000 is already locked and return a random port.
Potential solution?
Maybe a possible workaround is to allow for passing in an array of hosts, or an option to check all localhost variants?
The text was updated successfully, but these errors were encountered:
dylang
changed the title
Feature request: Available port for any localhost host valu (localhost, 0.0.0.0, 127.0.0.1)
Feature request: Available port for any localhost host (localhost, 0.0.0.0, 127.0.0.1)
May 29, 2020
If
server.listen
is used with ahost
, thenget-port
only returns the correct result if the samehost
value is provided.This works, because we put in the host
localhost
, matching above:However, when you don't know what host was used in the other project, or what host will be used in yours, you could be in trouble:
If that 3000 port is then used later in your code with
localhost
, it will fail.This might be a deficiency or feature in
libev
, or I'm not understanding how port binding works when the host is provided.Workaround 1
Always use the same host when creating your server as used when running
get-port
. I'm finding that to not always be feasible.Workaround 2
Potential solution?
Maybe a possible workaround is to allow for passing in an array of
hosts
, or an option to check alllocalhost
variants?The text was updated successfully, but these errors were encountered: