You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make sure you have localhost defined as 127.0.0.1 in your /etc/hosts, but no IPv6 ::1 definition.
Run:
constdns=require('dns')constCacheableLookup=require("cacheable-lookup");dns.lookup('localhost',{family: 6},(err,result)=>console.log('dns',err,result));constcacheable=newCacheableLookup();cacheable.servers=['1.1.1.1'];// Or any other remote DNS servercacheable.lookup('localhost',{family: 6},(err,result)=>console.log('cacheableLookup',err,result));
Having only IPv4 localhost defined but no IPv6 might seem contrived, but it's actually the default in many places, including all Ubuntu releases (see https://gist.github.com/ghoneycutt/e531984406b4b86ace687ea8958a6dc3). localhost can still be resolved to ::1 for IPv6 on these machines, it's just that it's handled elsewhere (no idea why).
This means that on most Ubuntu machines (and probably others) http.get('localhost', { family: 6, lookup: cacheableLookup.lookup }) with a DNS server configured will always incorrectly fail to resolve.
This happens because:
The family is set to 6
There's a server defined, so cacheable lookup sends a request there first
That returns ENOTFOUND, so cacheable lookup tries to use dns.lookup and cache the result
Cacheable-lookup doesn't pass the family to that call and instead always passes{ all: true }, presumably to maximize the fallback caching.
dns.lookup({ all: true }) actually returns only the IPv4 address from /etc/hosts, with no IPv6 value, even though dns.lookup({ family: 6 }) can successfully get the IPv6 result. Presumably this is because it stops once it finds an answer in /etc/hosts?
That last step might seem like bad Node.js behaviour, but it's also true in Python apparently so I expect it's something that comes from Linux's DNS resolution itself.
I think this will affect any lookup where only an IPv4 or IPv6 address is available in the hosts file - requests for the other family will simply fail unexpectedly. Haven't tested other OS, no idea if this can happen elsewhere too.
The text was updated successfully, but these errors were encountered:
Repro:
localhost
defined as 127.0.0.1 in your /etc/hosts, but no IPv6::1
definition.Having only IPv4 localhost defined but no IPv6 might seem contrived, but it's actually the default in many places, including all Ubuntu releases (see https://gist.github.com/ghoneycutt/e531984406b4b86ace687ea8958a6dc3).
localhost
can still be resolved to::1
for IPv6 on these machines, it's just that it's handled elsewhere (no idea why).This means that on most Ubuntu machines (and probably others)
http.get('localhost', { family: 6, lookup: cacheableLookup.lookup })
with a DNS server configured will always incorrectly fail to resolve.This happens because:
{ all: true }
, presumably to maximize the fallback caching.dns.lookup({ all: true })
actually returns only the IPv4 address from /etc/hosts, with no IPv6 value, even thoughdns.lookup({ family: 6 })
can successfully get the IPv6 result. Presumably this is because it stops once it finds an answer in /etc/hosts?That last step might seem like bad Node.js behaviour, but it's also true in Python apparently so I expect it's something that comes from Linux's DNS resolution itself.
I think this will affect any lookup where only an IPv4 or IPv6 address is available in the hosts file - requests for the other family will simply fail unexpectedly. Haven't tested other OS, no idea if this can happen elsewhere too.
The text was updated successfully, but these errors were encountered: