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

Localhost lookup and default host settings #722

Closed
nodech opened this issue May 11, 2022 · 2 comments
Closed

Localhost lookup and default host settings #722

nodech opened this issue May 11, 2022 · 2 comments

Comments

@nodech
Copy link
Contributor

nodech commented May 11, 2022

Recently I ran into the issue "localhost" not being consistently resolved to the same loopback address. Sometimes it would lookup IPv6 loopback ::1 and sometimes to IPv4 127.0.0.1. After investigation I figured out that resolved IP depended on the nodejs version and I had different nodejs version in different shells. So v16 was resolving localhost to IPv4 and v18 to IPv6. I am not 100% sure this behavior is consistent with other systems, but here is the way to reproduce:

  $ # Switch to node v16
  $ node -v && node -e 'dns.lookup("localhost", (_, ip) => console.log(ip))'
  v16.14.0
  127.0.0.1

  $ # Switch to node v18
  $ node -v && node -e 'dns.lookup("localhost", (_, ip) => console.log(ip))'
  v18.0.0
  ::1

Recent nodejs release v18, specifically nodejs/node#41431 PR is the source of this difference and I have not gone deeper to why for now. Important thing is that we can't 100% say what it will bind to. I think just using 127.0.0.1 by default will more consistent.

@nodech
Copy link
Contributor Author

nodech commented May 11, 2022

@lukeburns

@pinheadmz
Copy link
Member

confirmed, great:

--> sudo n 18
   installed : v18.1.0 (with npm 8.8.0)
-->  node -v && node -e 'dns.lookup("localhost", (_, ip) => console.log(ip))'
v18.1.0
::1
--> sudo n 16
   installed : v16.15.0 (with npm 8.5.5)
-->  node -v && node -e 'dns.lookup("localhost", (_, ip) => console.log(ip))'
v16.15.0
127.0.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants