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 requests do not timeout #39562

Closed
nemanjan00 opened this issue Jul 28, 2021 · 5 comments
Closed

DNS requests do not timeout #39562

nemanjan00 opened this issue Jul 28, 2021 · 5 comments
Labels
dns Issues and PRs related to the dns subsystem.

Comments

@nemanjan00
Copy link

Version

v16.5.0

Platform

Linux terminator 5.13.5-zen1-1-zen #1 ZEN SMP PREEMPT Sun, 25 Jul 2021 18:03:00 +0000 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

Run this code:

const dns = require("dns");

const resolver = new dns.Resolver({
	timeout: 5 * 1000
});

resolver.setServers([
	"123.123.123.123"
]);


resolver.resolve4("myip.opendns.com", (error, ip) => {
	console.log(error, ip);
});

How often does it reproduce? Is there a required condition?

It fails every single time

What is the expected behavior?

dns.TIMEOUT is returned as error in callback.

What do you see instead?

Request never times out.

Additional information

No response

@targos targos added the dns Issues and PRs related to the dns subsystem. label Jul 28, 2021
@targos
Copy link
Member

targos commented Jul 28, 2021

@nodejs/dns

@ghost
Copy link

ghost commented Jul 29, 2021

Using the latest version of this repo, a timeout is given for me after ~50 seconds for a timeout of 5000.

Initially it looks like the timeout being used is 10 * the timeout provided, but after a little further testing, I'm not so sure...

timeout: 300 times out after ~5s
timeout: 1000 times out after ~16s

Can you confirm anything similar @nemanjan00?

I'll do some digging in the meantime and update the thread if I find anything of interest.

@nemanjan00
Copy link
Author

I get pretty much identical results

Sounds like with some tuning I can get expected timeout, but, again, I do not want it to be fixed without me figuring out and having incorrect timeout :D

Implemented additional timeout around it and hopefully it will be fixed :D

@oluan
Copy link
Contributor

oluan commented Jul 31, 2021

This is due to c-ares (the lib underneath Node dns lib) by default, it retries timeout 4 times.
From c-ares documentation: After the first try, the timeout algorithm becomes more complicated, but scales linearly with the value of timeout.

That's why 300 * 1 + 3 retries = ~5s, for example.

I went ahead and added 'tries' as an option for Resolver options.

With that changes this:

const dns = require('dns');

const resolver = new dns.Resolver({
    timeout: 5 * 1000,
    tries: 1,
});

resolver.setServers([
    "123.123.123.123"
]);

resolver.resolve4("myip.opendns.com", (err, ip) => {
    if (err) {
        console.error(err);
    } else console.log(ip);
})

Will correctly throw an exception after 5000ms.

The pull request: #39610

@tniessen
Copy link
Member

tniessen commented Aug 8, 2021

It seems that this is resolved now that #39610 was merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dns Issues and PRs related to the dns subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants