Repository navigation
Conversation
Requests for the same hostname that arrive while a lookup is still in flight now wait for that lookup instead of starting their own, so a cold or expired cache no longer triggers a burst of identical lookups. Each waiting request still picks its own address from the cached records. A failed lookup rejects every waiting request and is not left pending, so the next request retries it. Requests with per-request `dns` options keep their own lookup. Fixes nodejs#5974 Signed-off-by: ump45nose <52391318+ump45nose@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5975 +/- ##
==========================================
+ Coverage 91.53% 91.55% +0.01%
==========================================
Files 113 113
Lines 43597 43623 +26
==========================================
+ Hits 39908 39937 +29
+ Misses 3689 3686 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
3 of 7 tasks
Contributor
Author
|
Merged latest Previous run was green on Node 22/24/25/26 aside from one likely-unrelated flake in |
This branch has not been deployed
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.
This relates to...
Fixes #5974
Rationale
When the DNS interceptor has no usable records for a hostname (cold cache, or every cached record has expired), each request starts its own
lookup(). A burst of concurrent requests to the same host therefore produces a burst of identical lookups; the reproduction in #5974 sees 100 lookups for 100 concurrent requests.Changes
Bug Fixes
lib/interceptor/dns.js:DNSInstancekeeps a per-hostname list of callbacks waiting on an in-flight lookup. Requests that arrive while a lookup for the same hostname is pending join it instead of starting another one. When the lookup completes the records are stored once and each waiting request still runspick()with its own origin (so ports/protocols are preserved and round-robin keeps working). A failed lookup rejects every waiting request and the pending entry is removed, so the next request retries.dnsoptions (opts.dns) keep their own lookup, since they may resolve differently.docs/docs/api/Interceptors.md: one sentence describing the shared in-flight lookup.test/interceptors/dns.js: two regression tests — 20 concurrent requests share one lookup and a second batch uses the cache; 5 concurrent requests sharing a failed lookup all reject withENOTFOUND, and the following request performs a fresh lookup.Features
N/A
Breaking Changes and Deprecations
N/A
Testing (Node.js v22.20.0, Linux)
node --test --test-name-pattern='#5974' test/interceptors/dns.js: 2/2 pass with the fix; both fail on unmodifiedmain(20 lookups instead of 1; not all requests rejected by the failed lookup).{ coldCacheLookups: 1, warmCacheLookups: 0 }with the fix,{ coldCacheLookups: 100, warmCacheLookups: 0 }onmain.node --test test/interceptors/dns.js: of 37 tests, 33 pass (including the two new ones), 3 are skipped because IPv6 localhost is unavailable here, and 1 fails:Should respect DNS origin hostname for SNI on TLS, withERR_SSL_SSL/TLS_ALERT_HANDSHAKE_FAILURE; it fails the same way on unmodifiedmain, and leaves the run hanging until my 600 s timeout. I'm relying on CI for that one.node --test test/interceptors/origin-isolation.js test/interceptors/deduplicate.js: 73/73 pass.npx eslint lib/interceptor/dns.js test/interceptors/dns.js: clean.Status
AI assistance was used to help prepare and verify this change.