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

Cacheable lookup responds with ESERVFAIL while native dns.resolve works #68

Open
lokesh411 opened this issue Sep 7, 2022 · 10 comments
Open
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@lokesh411
Copy link

Hello,
I have come across a issue where cacheable.lookup or cacheable.lookupAsync was giving ESERVFAIL while dns.resolve or dns.lookup worked perfectly fine.
When i went through the code, i found out that we are trying to resolve for both IPv4 and IPv6 addresses for the domain. If the server sends failure (ESERVFAIL) for the dns lookup since the hostname doesn't exists in the respective IP family, even if it can resolve for the other IP family the library throws the error.
Reference:
[https://github.com/szmarczak/cacheable-lookup/blob/master/source/index.js#L244]
Any reasons where we should lookup for both IPv4 and IPv6 addresses?
const [A, AAAA] = await Promise.all([ ignoreNoResultErrors(this._resolve4(hostname, ttl)), ignoreNoResultErrors(this._resolve6(hostname, ttl)) ]);
For a domain i found that resolve4 was working fine but resolve6 was failing with ESERVFAIL error

@vinaycr7
Copy link

vinaycr7 commented Sep 7, 2022

I have also faced the same issue

@szmarczak
Copy link
Owner

szmarczak commented Sep 7, 2022

Duplicate of #52. What does ESERVFAIL mean? I couldn't find anything in the internet about this. Not sure if we should treat this an empty response (it would work in that case), but first I need to know the meaning of the error.

@szmarczak szmarczak added the question Further information is requested label Sep 7, 2022
@lokesh411
Copy link
Author

https://bluecatnetworks.com/blog/the-top-four-dns-response-codes-and-what-they-mean/
@szmarczak This explains all the the DNS errors, ESERVFAIL means that the query failed because the answer cannot be given, means the server refuses to give response for the query.
Shouldn't be handled in a way where we would get only one query IPv4 and if the DNS is not present we could call IPv6 right?

@szmarczak
Copy link
Owner

The website doesn't work for me. Can you post a screenshot or give another source please?

@lokesh411
Copy link
Author

Screenshot 2022-09-08 at 7 34 28 PM

[](url)

Screenshot 2022-09-08 at 7 35 09 PM

@szmarczak
Copy link
Owner

That doesn't seem to be correct. I just used Google again and this time found this:

default("Server failure: unable to process this query due to a problem with the name server"):
   return SERVFAIL

"catch-all" SERVFAIL: something went wrong but what exactly?

When a user receives SERVFAIL, the failure can be one of the following:

The stub resolver fails to send the request.
The stub resolver doesn’t get a response.
The recursive resolver, which the stub resolver sends its query to, is overloaded.
The recursive resolver is unable to communicate with upstream authoritative servers.
The recursive resolver fails to verify the DNSSEC chain.
The authoritative server takes too long to respond.

In such cases, it is nearly impossible for the user to know exactly what’s wrong. The resolver is usually the one to be blamed, because, as an agent, it fails to get back the answer, and doesn’t return a clear reason for the failure in the response.

Which means that there's an internal server error. In that case we definitely want to throw an error. If a server doesn't support IPv6, it shouldn't respond with SERVFAIL.

Closing as duplicate of #52

@lokesh411
Copy link
Author

Yeah in some DNS servers this happens, when i point to CF dns it returns with ENOTFOUND. But we don't have to query for IPv4 and IPv6 addresses right on resolve()

@szmarczak
Copy link
Owner

Correct, that's part of #52

@lokesh411
Copy link
Author

The problem still exists, when i query for some domains like staging.camsrepository.com, CF DNS resolver throws ESERVFAIL. Since the implementation is querying for both resolve4 and resolve6, should we use promise.allSettled instead of promise.all
Code reference: https://github.com/szmarczak/cacheable-lookup/blob/master/source/index.mjs#L251

@szmarczak szmarczak reopened this Jan 7, 2023
@szmarczak szmarczak added enhancement New feature or request help wanted Extra attention is needed and removed question Further information is requested labels Jan 7, 2023
@SuperOleg39
Copy link

SuperOleg39 commented Jun 26, 2023

Hello! Is this temporary workaround correct?

        const cacheable = new CacheableLookup({
            cache,
            maxTtl,
          });

          const originalLookup = cacheable.lookup;

          cacheable.lookup = (hostname, options, callback) => {
            if (hostname === 'localhost') {
              return dns.lookup(hostname, options, callback);
            }
            originalLookup.call(cacheable, hostname, options, callback);
          };

          cacheable.install(http.globalAgent);
          cacheable.install(https.globalAgent);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants