-
Notifications
You must be signed in to change notification settings - Fork 298
Closed
Description
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.
Metadata
Metadata
Assignees
Labels
No labels