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
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:
Listen on ::, catch the EAFNOSUPPORT error and listen again on 0.0.0.0 on error.
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.
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.
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.
Activity
imZack commentedon Dec 23, 2017
+1, we should have something like
net.createServer({ ipv6only: true })#9390 (comment)silverwind commentedon Dec 23, 2017
Putting it on
createServerseems wrong to me, it's a flag specific to the listen action, so should be on listen/bind.cjihrig commentedon 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 commentedon Jul 20, 2018
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.[-]ipv6only listen/bind option[/-][+]ipv6only listen option[/+]net,dgram: add ipv6Only option for net and dgram
net,dgram: add ipv6Only option for net and dgram
net,dgram: add ipv6Only option for net and dgram
net,dgram: add ipv6Only option for net and dgram
net,dgram: add ipv6Only option for net and dgram