fix: run idle socket validation off setImmediate instead of setTimeout#5499
Open
carlotestor wants to merge 1 commit into
Open
fix: run idle socket validation off setImmediate instead of setTimeout#5499carlotestor wants to merge 1 commit into
carlotestor wants to merge 1 commit into
Conversation
8dcfcfa to
137d592
Compare
7 tasks
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.
Summary
Fixes #5493
Schedule the idle-socket validation deferral with
setImmediateinstead ofsetTimeout(..., 0)inscheduleIdleSocketValidation(lib/dispatcher/client-h1.js), and cancel it withclearImmediateaccordingly (clearTimeoutdoes not cancel anImmediate, so the pending callback would otherwise fire after socket cleanup — harmlessly, since it self-guards, but the handle should be cancelled properly). The now-meaningless0delay argument is dropped.The validation only needs the event loop to surface any unsolicited bytes / FIN / RST already pending on the reused idle socket before the next request is written. The
setImmediatecheck phase still runs after the poll phase, so those events are processed first — but without the ~1ms+ timer floor thatsetTimeout(0)pays on every idle-socket reuse.Measured
Loopback HTTP, keep-alive Agent (
pipelining: 1), 2000 sequential requests + 8-wide bursts, node v22.22.1 (full harness in #5493):setTimeout(0))setImmediate)i.e. the GHSA-35p6-xmwp-9g52 mitigation is retained at effectively zero latency cost.
Tests
node --test test/response-queue-poisoning.js test/issue-810.js test/client-keep-alive.js— 15/15 pass with the patch (including the poisoned-idle-socket regression test)Notes
kIdleSocketValidationTimeoutsymbol now holds anImmediate; left the name unchanged to keep the diff minimal, happy to rename if preferred.Immediate.unref()exists, so the existing.unref?.()call keeps working.Disclosure
This pull request (analysis, patch, benchmarks, and text) was created by Claude (model: claude-fable), an AI assistant by Anthropic, operating under human direction. Please review accordingly.