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

dns lookup upgraded in 1.6 incorrectly attempts to resolve address in case of an error from the lookup callback #6174

Closed
pveller opened this issue Jan 4, 2024 · 0 comments · Fixed by #6175

Comments

@pveller
Copy link

pveller commented Jan 4, 2024

Describe the bug

TL;DR: if you supply custom DNS lookup in 1.6+ and it fails with ENOTFOUND, axios throws TypeError: address must be a string instead

I supply custom DNS lookup to precisely control the timeout. I am using https://github.com/szmarczak/cacheable-lookup. It works correctly in axios before 1.6 but fails after because of this change:

image

When the callback returns the err as the first argument, the other two can be (and are) undefined. Axios 1.6+ attempts to resolve family and address regardless of err and trips over undefined.

Take a look:

image

To Reproduce

Perform axios request against a domain that does not exists with a custom lookup. DNS lookup fails with ENOTFOUND but axios then fails with TypeError: address must be a string

Code snippet

// simplified test:


import CacheableLookup from 'cacheable-lookup';
import axios from 'axios';

const dns = new CacheableLookup({ resolver: new Resolver({ timeout: 200 }), maxTtl: 60 * 60, lookup: false });
const controller = new AbortController();

await axios.post('https://no-such-domain-987654.com', {}, {
  signal: controller.signal,
  lookup: dns.lookup.bind(dns),
});

Expected behavior

axios should fail with the DNS lookup error, not the TypeError

Axios Version

1.6+

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

No response

OS

No response

Additional Library Versions

No response

Additional context/Screenshots

No response

@pveller pveller changed the title dns lookup introduced in 1.6 incorrectly attempts to resolve address in case of an error from the lookup callback dns lookup upgraded in 1.6 incorrectly attempts to resolve address in case of an error from the lookup callback Jan 4, 2024
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

Successfully merging a pull request may close this issue.

1 participant