CodePark/ questions / DNS
START PRACTICINGPRACTICE
Backend question · OS, networking & Linux › DNS

Which statement about Node's dns.lookup() and dns.resolve4() is correct?

dns.lookup() uses the OS resolver (getaddrinfo) on the libuv thread pool and honours /etc/hosts, while dns.resolve4() queries DNS servers over the network and ignores /etc/hosts

dns.lookup() uses the OS resolver (getaddrinfo) on the libuv thread pool and honours /etc/hosts. dns.resolve4() queries DNS servers over the network and ignores /etc/hosts.

dns.lookup() is what http.get and net.connect use by default. It behaves like other programs on the same machine. But each call blocks one thread in the thread pool. So slow DNS can starve fs and crypto work, which use the same pool.

The
dns.resolve*() functions use the c-ares library. They query DNS servers directly, without the thread pool. So "dns.resolve4() runs on the libuv thread pool" has it backwards.

Node caches neither one. So "
dns.lookup() caches answers inside Node for the record's TTL" is wrong.