Skip to content

dns.lookup blocks filesystem I/O #8436

Closed
@ottobonn

Description

@ottobonn
  • Version: v4.5.0
  • Platform: Linux jessie 3.16.0-4-amd64 # 1 SMP Debian 3.16.7-ckt25-2+deb8u3 (2016-07-02) x86_64 GNU/Linux
  • Subsystem: dns

Hi all,

I'm posting this issue as a continuation of an issue originally opened against node-serialport: serialport/node-serialport#797

On networks with slow DNS response, or where DNS requests time out and fail, we observe that the blocking calls to getaddrinfo issued by dns.lookup saturate Node's libuv threadpool and delay our serialport or filesystem IO.

It looks like this issue has come up many times before. The most pertinent example I could find is nodejs/node-v0.x-archive#2868, which outlines exactly this issue. However, it was closed in favor of nodejs/node-v0.x-archive#8475, in which the API of net.connect was changed to allow a user-specified DNS resolution handler.

The original proposal of issue 2868, which included a change to dns.lookup, seems to have been lost in the consolidation to issue 8475. In our case, we'd like to be able to use the OS-level DNS facilities like a local DNS cache, so using dns.resolve does not seem to be an equivalent substitute to using dns.lookup. Furthermore, our application uses multiple high-level modules that wrap REST APIs with their own request modules, so changing every call to net.connect to use a custom DNS function is not feasible.

There seems to be a relevant open issue against libuv on the matter at libuv/libuv#203. Through various issue reports, I've seen proposals in libuv to use getaddrinfo_a, to segregate the threadpools, or to cap the number of threads DNS requests could use, to avoid DNS requests starving all other IO.

Unfortunately, although the synchronicity of dns.lookup is documented at https://nodejs.org/api/dns.html#dns_implementation_considerations, its behavior is not intuitive given that other network requests are truly asynchronous, and it has resulted in many downstream issues, including our seeming issue with serialport.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.dnsIssues and PRs related to the dns subsystem.libuvIssues and PRs related to the libuv dependency or the uv binding.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions