Files
Orgad Shaneh ec4d4c2950 dns: coalesce identical concurrent lookup() requests
When multiple callers issue dns.lookup() for the same (hostname, family,
hints, order) concurrently, only one getaddrinfo call is now dispatched
to the libuv threadpool.  All callers share the result.

getaddrinfo is a blocking call that runs on the libuv threadpool (capped
at 4 threads by default, with a slow I/O concurrency limit of 2).  When
DNS resolution is slow - e.g. ~10-20 s per call due to a misbehaving
resolver - identical requests queue behind each other, causing timeouts
that grow linearly with the number of concurrent callers:

  Before: 100 parallel lookup('host') -> 50 batches × 10 s = 500+ s
  After:  100 parallel lookup('host') -> 1 getaddrinfo  call = ~10 s

This is particularly severe on WSL, where the DNS relay rewrites QNAMEs
in responses (appending the search domain), causing glibc to discard
them as non-matching and wait for a 5s timeout per retry.

The coalescing is keyed on (hostname, family, hints, order) so lookups
with different options still get separate getaddrinfo calls.  Each
caller independently post-processes the shared raw result (applying the
'all' flag, constructing address objects, etc.).

Signed-off-by: Orgad Shaneh <orgad.shaneh@audiocodes.com>
Fixes: https://github.com/nodejs/node/issues/62503
PR-URL: https://github.com/nodejs/node/pull/62599
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2026-11-06 03:18:17 +00:00
..