dns: support AbortSignal in dns.lookup() and dns.promises.lookup()#62528
Draft
orgads wants to merge 1 commit intonodejs:mainfrom
Draft
dns: support AbortSignal in dns.lookup() and dns.promises.lookup()#62528orgads wants to merge 1 commit intonodejs:mainfrom
orgads wants to merge 1 commit intonodejs:mainfrom
Conversation
Collaborator
|
Review requested:
|
Add a `signal` option to both `dns.lookup()` and `dns.promises.lookup()`
that accepts an AbortSignal, allowing callers to cancel pending lookups.
When `getaddrinfo` blocks a libuv thread for an extended period (e.g. ~10s
on EAI_AGAIN), new lookups queue behind the blocked threads and the number
of unresolved promises grows without bound. Each pending promise holds
references to the calling closure, preventing GC and causing a memory leak
in long-running servers under sustained DNS failure.
With this change, callers can abort stale lookups:
const ac = new AbortController();
setTimeout(() => ac.abort(), 5000);
await dns.promises.lookup(host, { signal: ac.signal });
If the signal is already aborted, the call rejects/calls back immediately
without dispatching to libuv. If aborted while pending, the promise is
rejected (or callback called) with an AbortError and the late oncomplete
from libuv is silently ignored.
Fixes: nodejs#62503
PR-URL: nodejs#62528
197608e to
67e8f47
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62528 +/- ##
==========================================
- Coverage 89.72% 89.71% -0.01%
==========================================
Files 695 695
Lines 214106 214175 +69
Branches 41002 41020 +18
==========================================
+ Hits 192096 192157 +61
+ Misses 14077 14070 -7
- Partials 7933 7948 +15
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a
signaloption to bothdns.lookup()anddns.promises.lookup()that accepts an AbortSignal, allowing callers to cancel pending lookups.When
getaddrinfoblocks a libuv thread for an extended period (e.g. ~10s on EAI_AGAIN), new lookups queue behind the blocked threads and the number of unresolved promises grows without bound. Each pending promise holds references to the calling closure, preventing GC and causing a memory leak in long-running servers under sustained DNS failure.With this change, callers can abort stale lookups:
If the signal is already aborted, the call rejects/calls back immediately without dispatching to libuv. If aborted while pending, the promise is rejected (or callback called) with an AbortError and the late oncomplete from libuv is silently ignored.
Fixes: #62503