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.lookup('localhost', { all: true}) returns only ::1 with Node.js v22.12, while v22.11 returned both ::1 and 127.0.0.1 #56137

Closed
jasongin opened this issue Dec 5, 2024 · 1 comment · Fixed by #56224
Labels
confirmed-bug Issues with confirmed bugs. dns Issues and PRs related to the dns subsystem. windows Issues and PRs related to the Windows platform.

Comments

@jasongin
Copy link
Member

jasongin commented Dec 5, 2024

Version

v22.12.0

Platform

Windows 11 (Microsoft Windows NT 10.0.26100.0 x64)

Subsystem

dns

What steps will reproduce the bug?

On my Windows 11 system, the localhost hostname resolves to both ::1 and 127.0.0.1, as confirmed by PowerShell Resolve-DnsName:

PS> Resolve-DnsName localhost
Name             Type   TTL   Section    IPAddress
----             ----   ---   -------    ---------
localhost        AAAA   1200  Question   ::1
localhost        A      1200  Question   127.0.0.1

And with Node.js v22.11 (and v20, and v18), both addresses are returned by a DNS lookup, as expected:

PS> node -v
v22.11.0
PS> node -e "require('dns').lookup('localhost', {all: true}, (err, addresses) => console.log(JSON.stringify(addresses, null, '  ')))"
[
  {
    "address": "::1",
    "family": 6
  },
  {
    "address": "127.0.0.1",
    "family": 4
  }
]

However with Node.js v22.12, only ::1 is returned:

PS> node -v
v22.12.0
PS> node -e "require('dns').lookup('localhost', {all: true}, (err, addresses) => console.log(JSON.stringify(addresses, null, '  ')))"
[
  {
    "address": "::1",
    "family": 6
  }
]

How often does it reproduce? Is there a required condition?

It repros consistently on Windows.

I do not see the same problem on Linux: after editing /etc/hosts to include dual mappings for localhost, I do see both addresses returned from the Node.js DNS lookup, and it is consistent between Node.js v22.11 and v22.12.

What is the expected behavior? Why is that the expected behavior?

I found this bug because we have some Node.js test code that needs to connect to a port on localhost without knowing whether the local server is listening on the IPv4 or IPv6 localhost. It actually uses net.createConection({..., autoSelectFamily: true }), but the problem seems to be with the DNS resolution before the "happy eyeballs" algorithm gets a chance to auto-select an address family. Because only ::1 is tried, the connection fails if the local server was actually listening on IPv4.

What do you see instead?

Error: connect ECONNREFUSED ::1:51793

...when the server was actually listening on 127.0.0.1:51793

Additional information

No response

@jakecastelli jakecastelli added dns Issues and PRs related to the dns subsystem. windows Issues and PRs related to the Windows platform. labels Dec 5, 2024
@aduh95 aduh95 added the confirmed-bug Issues with confirmed bugs. label Dec 10, 2024
@lpinca
Copy link
Member

lpinca commented Dec 11, 2024

Bisecting points to ecedcba as the first bad commit.

lpinca added a commit to lpinca/node that referenced this issue Dec 11, 2024
aduh95 pushed a commit that referenced this issue Dec 18, 2024
Fixes: #56137
Refs: #56223
PR-URL: #56224
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
aduh95 pushed a commit that referenced this issue Dec 18, 2024
Fixes: #56137
Refs: #56223
PR-URL: #56224
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
@targos targos marked this as a duplicate of #56311 Dec 19, 2024
ruyadorno pushed a commit that referenced this issue Dec 20, 2024
Fixes: #56137
Refs: #56223
PR-URL: #56224
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
ruyadorno pushed a commit that referenced this issue Dec 21, 2024
Fixes: #56137
Refs: #56223
PR-URL: #56224
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. dns Issues and PRs related to the dns subsystem. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants