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

In Node v20.12.0+ IPv6 address lookups fail in CacheableLookup #85

Open
pimterry opened this issue Nov 27, 2024 · 0 comments
Open

In Node v20.12.0+ IPv6 address lookups fail in CacheableLookup #85

pimterry opened this issue Nov 27, 2024 · 0 comments

Comments

@pimterry
Copy link
Contributor

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.

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

1 participant