Skip to content

DNS requests do not timeout #39562

Description

@nemanjan00

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

Activity

  1. added
    dnsIssues and PRs related to the dns subsystem.
    on Jul 28, 2021
  2. targos commented on Jul 28, 2021

    @targos
    Member

    @nodejs/dns

  3. nemanjan00 commented on Jul 29, 2021

    @nemanjan00
    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

  4. oluan commented on Jul 31, 2021

    @oluan
    Contributor

    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

  5. tniessen commented on Aug 8, 2021

    @tniessen
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    dnsIssues and PRs related to the dns subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions