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

dns docs are missing that family = 0 for dns.lookup is allowed #28159

Closed
daprahamian opened this issue Jun 10, 2019 · 2 comments
Closed

dns docs are missing that family = 0 for dns.lookup is allowed #28159

daprahamian opened this issue Jun 10, 2019 · 2 comments
Labels
dns Issues and PRs related to the dns subsystem. doc Issues and PRs related to the documentations.

Comments

@daprahamian
Copy link

  • Node.js Version: 12.2
  • OS: macOs
  • Scope (install, code, runtime, meta, other?): runtime
  • Module (and version) (if relevant): dns, net, tls

Quick question: is dns.lookup(url, 0, callback) supported as part of Node's API? The documentation says Must be 4 or 6, and any positive integer other than 4 or 6 will return a TypeError [ERR_INVALID_OPT_VALUE]: The value "2" is invalid for option "family". But passing in 0 does not error. Is this expected? If so, is this something stable that developers can rely on?

// The following are all expected to work
dns.lookup('www.google.com', 4, err => {
  console.log(err); // null
});
dns.lookup('www.google.com', 6, err => {
  console.log(err); // null
});
dns.lookup('www.google.com', err => {
  console.log(err); // null
});

// The following should error
try {
  dns.lookup('www.google.com', 1, () => {});
} catch (e) {
  console.log(e); // TypeError [ERR_INVALID_OPT_VALUE]: The value "1" is invalid for option "family"
}
try {
  dns.lookup('www.google.com', 2, () => {});
} catch (e) {
  console.log(e); // TypeError [ERR_INVALID_OPT_VALUE]: The value "2" is invalid for option "family"
}
try {
  dns.lookup('www.google.com', 3, () => {});
} catch (e) {
  console.log(e); // TypeError [ERR_INVALID_OPT_VALUE]: The value "3" is invalid for option "family"
}
try {
  dns.lookup('www.google.com', 5, () => {});
} catch (e) {
  console.log(e); // TypeError [ERR_INVALID_OPT_VALUE]: The value "5" is invalid for option "family"
}

// Asking about this one:
dns.lookup('www.google.com', 0, err => {
  console.log(err); // null <-- is this correct?
});
@addaleax
Copy link
Member

0 stands for AF_UNSPEC, which, quoting the man page, means:

The value AF_UNSPEC indicates that getaddrinfo() should return socket addresses for any address family (either IPv4 or IPv6, for example) that can be used with node and service.

So, the Node.js documentation is clearly wrong, and omitting an important feature here (although it’s the default behaviour). I’m moving this over to the main repo as it’s a documentation bug.

@addaleax addaleax changed the title is family = 0 for dns.lookup allowed? dns docs are missing that family = 0 for dns.lookup is allowed Jun 10, 2019
@addaleax addaleax transferred this issue from nodejs/help Jun 10, 2019
@addaleax addaleax added dns Issues and PRs related to the dns subsystem. doc Issues and PRs related to the documentations. labels Jun 10, 2019
cjihrig added a commit to cjihrig/node that referenced this issue Jun 11, 2019
@ZYSzys ZYSzys closed this as completed in 282e2f6 Jun 14, 2019
@ZYSzys
Copy link
Member

ZYSzys commented Jun 14, 2019

Fixed via #28163.

BridgeAR pushed a commit that referenced this issue Jun 17, 2019
Fixes: #28159

PR-URL: #28163
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this issue Jun 18, 2019
Fixes: #28159

PR-URL: #28163
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
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
dns Issues and PRs related to the dns subsystem. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants