Closed pimterry closed 3 years ago
Good catch! Thanks for the very detailed issue, I can reproduce this locally.
I think the solution is to duplicate the dns.lookup
call for now, so it gets queried separately for IPv4 and IPv6.
Released 6.0.2
:tada:
Amazing, thanks for the quick merge & release! :tada:
Repro:
localhost
defined as 127.0.0.1 in your /etc/hosts, but no IPv6::1
definition.Run:
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.