Skip to content

DNS server caching breaks changing networks in runtime #14086

@elad

Description

@elad
  • Version: 8.1.3
  • Platform: macOS Sierra
  • Subsystem: DNS

I'm experiencing an odd issue when resolving AAAA hostnames using the dns module as the network changes "below".

Consider the following program:

const dns = require('dns');

setInterval(() => {
  dns.resolve('www.google.com', 'AAAA', (err, records) => { console.log(err, records); });
}, 1000);

If I run this program while connected to an IPv6 network, it works. If I run this program while connected to an IPv6 VPN, it also works.

However, if I run this program while connected to an IPv6 network and while it runs connect to the IPv6 VPN, I get the following output:

$ node test.js
null [ '2a00:1450:400e:800::2004' ]
[...a lot of these...]
{ Error: queryAaaa ECONNREFUSED www.google.com
    at errnoException (dns.js:50:10)
    at QueryReqWrap.onresolve [as oncomplete] (dns.js:235:19)
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'queryAaaa',
  hostname: 'www.google.com' } undefined
[...a lot of these...]

This happens because DNS servers are cached. I'm not too familiar with the code, but from briefly skimming through src/cares_wrap.cc it seems that AresEnsureServers() -- which is called before each query to ensure DNS servers are available -- immediately returns under certain circumstances that are true in the above case and probably many other.

While I don't suggest disabling DNS server caching, it seems that there's no way to get DNS working in the scenario I described. At the very least, maybe there should be a function to force flushing of the DNS server cache? (e.g. dns.flush()) Alternatively, am I missing something and there is a way to get this to work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    caresIssues and PRs related to the c-ares dependency or the cares_wrap binding.dnsIssues and PRs related to the dns subsystem.feature requestIssues that request new features to be added to Node.js.stalledIssues and PRs that are stalled.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions