Skip to content

docs: dns docs for family = 0 and all = true is potentially misleading #51482

Description

@domdomegg

Affected URL(s)

https://nodejs.org/api/dns.html#dnslookuphostname-options-callback

Description of the problem

I think the docs are potentially misleading on the family = 0 dns lookup option.

Currently, the docs read: "The value 0 indicates that IPv4 and IPv6 addresses are both returned."

I initially interpreted this as "[NOT CORRECT] setting the family value to 0 and all to true will mean on a system that supports both IPv4 and IPv6, an IPv4 and IPv6 address will be returned"

However, what I think this actually means is "setting the family value to 0 and all to true will mean on a system that supports both IPv4 and IPv6, either an IPv4 or IPv6 address, or both will be returned - depending on the underlying DNS implementation"

As a short example demoing this behaviour (at least on Ubuntu 22.04.3, running Node v20.11.0):

require('node:dns').lookup('localhost', { all: true, family: 0 }, console.log)
// null [ { address: '127.0.0.1', family: 4 } ]

require('node:dns').lookup('localhost', { all: true, family: 4 }, console.log)
// null [ { address: '127.0.0.1', family: 4 } ]

require('node:dns').lookup('localhost', { all: true, family: 6 }, console.log)
// null [ { address: '::1', family: 6 } ]

Meaning if a user really does want both (rather than just accepts either), they should do two calls: one for IPv4 and one for IPv6 separately.

Some evidence for it being potentially confusing:

Also see #28159.

Activity

  1. added
    docIssues and PRs related to Node.js documentation.
    on Jan 16, 2024
  2. domdomegg commented on Jan 16, 2024

    @domdomegg
    ContributorAuthor

    The alternative angle is to view this as a potential feature for the dns module - where the behaviour of dns.lookup('localhost', { all: true, family: 0 }, console.log) is standardised across platforms to produce IPv4 and IPv6 results when available. Especially because even if documented, people still may depend on this behaviour because it works on some (most?) machines.

  3. duncanchiu409 commented on Jan 16, 2024

    @duncanchiu409
    Contributor

    The current implementation is "setting the family value to 0 and all to true will mean on a system that supports both IPv4 and IPv6, either an IPv4 or IPv6 address". If I am not wrong. :)

  4. added 2 commits that reference this issue on May 11, 2024
    952ae65
    6e07a76
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

    docIssues and PRs related to Node.js documentation.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions