镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

ipv6only listen option #17664

Description

@silverwind

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

  1. added
    dgramIssues and PRs related to UDP and the dgram module.
    feature requestIssues requesting new Node.js features.
    netIssues and PRs related to the net subsystem.
    on Dec 13, 2017
  2. imZack commented on Dec 23, 2017

    @imZack
    Contributor

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

  3. silverwind commented on Dec 23, 2017

    @silverwind
    ContributorAuthor

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

  4. cjihrig commented on Jul 20, 2018

    @cjihrig
    Contributor

    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.

  5. silverwind commented on Jul 20, 2018

    @silverwind
    ContributorAuthor

    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.

  6. removed
    dgramIssues and PRs related to UDP and the dgram module.
    on Jul 20, 2018
  7. changed the title [-]ipv6only listen/bind option[/-] [+]ipv6only listen option[/+] on Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.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