Skip to content

ipv6only listen option #17664

Closed
Closed
@silverwind

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.netIssues and PRs related to the net subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions