Description
Repro:
CL = require('cacheable-lookup');
cl = new CL();
cl.lookup('::ffff:127.0.0.1', console.log);
In Node v20.11.1 this returns the input address (this is the same behaviour as dns.lookup).
In Node v20.12.0, this still works fine with dns.lookup
, but with cacheable-lookup it throws:
Error: queryA EBADNAME ::ffff:127.0.0.1
at QueryReqWrap.onresolve [as oncomplete] (node:internal/dns/promises:275:17)
at QueryReqWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: undefined,
code: 'EBADNAME',
syscall: 'queryA',
hostname: '::ffff:127.0.0.1'
}
It seems that the validation in dns.resolve
has changed (probably due to changes in c-ares, though I can't spot the exact cause) so that IPv6 addresses now return EBADNAME in this case (IPv4 addresses do not, and dns.lookup hasn't change at all).
This happens because cacheable-lookup uses dns.resolve (which rejects this) before using dns.lookup (which would work), and ignoreNoResultErrors
does not ignore this error, and so the request fails.
This is a bit weird! It's unusual to do a DNS lookup for an IP obviously, but plenty of code does do this because it's simpler than trying to detect IPs and go down different code paths for that case, and it's clearly supported by the standard dns.lookup API.
To make this library consistent & drop-in compatible with dns.lookup, I think this should return the input address too.