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

ipv6only listen option #17664

Closed
silverwind opened this issue Dec 13, 2017 · 4 comments
Closed

ipv6only listen option #17664

silverwind opened this issue Dec 13, 2017 · 4 comments
Labels
feature request Issues that request new features to be added to Node.js. net Issues and PRs related to the net subsystem.

Comments

@silverwind
Copy link
Contributor

Currently, listening on the :: address will attempt to bind on IPv4 and IPv6, whatever is available. This works most of the time but a issue arises on Linux with the ipv6.disable=1 kernel option set (which can be default on certain NAS devices). With it, listening on :: results in a EAFNOSUPPORT error. To work around and still get a IPv4 socket, one would have to apply one of these workarounds:

  1. Listen on ::, catch the EAFNOSUPPORT error and listen again on 0.0.0.0 on error.
  2. Listen on :: and 0.0.0.0 and ignore both the EAFNOSUPPORT (can happen on ::) and EADDRINUSE (happens on the latter call when dual-stack actually works) errors.

To resolve above ugly error handling, I suggest exposing the existing UV_{TCP,UDP}_IPV6ONLY flags on server#listen and socket#bind via a new boolean option ipv6only. With the option set, one can listen on :: and 0.0.0.0 without any unexpected errors happening.

Related: nginx also features the ipv6only option, which has been enabled by default since v1.3.4.

@silverwind silverwind added dgram Issues and PRs related to the dgram subsystem / UDP. feature request Issues that request new features to be added to Node.js. net Issues and PRs related to the net subsystem. labels Dec 13, 2017
@imZack
Copy link
Contributor

imZack commented Dec 23, 2017

+1, we should have something like net.createServer({ ipv6only: true }) #9390 (comment)

@silverwind
Copy link
Contributor Author

Putting it on createServer seems wrong to me, it's a flag specific to the listen action, so should be on listen/bind.

@cjihrig
Copy link
Contributor

cjihrig commented Jul 20, 2018

This makes sense on the net side, but do we need this on the dgram side? On my machine at least, I seem unable to bind a 'udp6' socket on an IPv4 address, and vice versa.

@silverwind
Copy link
Contributor Author

unable to bind a 'udp6' socket on an IPv4 address

Yes, seems that's not possible, I get a "bind EINVAL" when attempting this, so it seems for UDP, the bound address family is dictated by the type of socket and the issue only applies to net.

@silverwind silverwind removed the dgram Issues and PRs related to the dgram subsystem / UDP. label Jul 20, 2018
@silverwind silverwind changed the title ipv6only listen/bind option ipv6only listen option Jul 20, 2018
oyyd added a commit to oyyd/node that referenced this issue Nov 21, 2018
For TCP servers, the dual-stack support is enable by default, i.e.
binding host "::" will also make "0.0.0.0" bound. This commit add
ipv6Only option in `net.Server.listen()` and `dgram.createSocket()`
methods which allows to disable dual-stack support. Support for
cluster module is also provided in this commit.

Fixes: nodejs#17664
@oyyd oyyd closed this as completed in 33a25b2 Nov 22, 2018
targos pushed a commit that referenced this issue Nov 24, 2018
For TCP servers, the dual-stack support is enable by default, i.e.
binding host "::" will also make "0.0.0.0" bound. This commit add
ipv6Only option in `net.Server.listen()` and `dgram.createSocket()`
methods which allows to disable dual-stack support. Support for
cluster module is also provided in this commit.

Fixes: #17664

PR-URL: #23798
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
rvagg pushed a commit that referenced this issue Nov 28, 2018
For TCP servers, the dual-stack support is enable by default, i.e.
binding host "::" will also make "0.0.0.0" bound. This commit add
ipv6Only option in `net.Server.listen()` and `dgram.createSocket()`
methods which allows to disable dual-stack support. Support for
cluster module is also provided in this commit.

Fixes: #17664

PR-URL: #23798
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
refack pushed a commit to refack/node that referenced this issue Jan 14, 2019
For TCP servers, the dual-stack support is enable by default, i.e.
binding host "::" will also make "0.0.0.0" bound. This commit add
ipv6Only option in `net.Server.listen()` and `dgram.createSocket()`
methods which allows to disable dual-stack support. Support for
cluster module is also provided in this commit.

Fixes: nodejs#17664

PR-URL: nodejs#23798
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. net Issues and PRs related to the net subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants