Repository navigation
Conversation
The keep-alive timer of an idle socket cannot fire while the event loop is blocked. When the next request is dispatched from the poll phase (an I/O callback, a server request handler, or a continuation after awaiting I/O), the idle socket validation added for GHSA-35p6-xmwp-9g52 completes in the check phase of the same loop iteration, before that timer fires and before a FIN received during the block is read. The request is then written to a socket that the server may already have closed, and fails with ECONNRESET. Record when the keep-alive timer is armed, and destroy the socket with an InformationalError instead of reusing it once its keep-alive timeout has passed. Nothing is running on the socket, so the pending requests are sent on a new connection. The check does not depend on kSocketUsed, so it also covers the experimental Milo parser, which never sets that symbol. Refs: nodejs/node#67292 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sfj4nEWQ4ovycNDjbvXcRs Signed-off-by: Matteo Collina <hello@matteocollina.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6171 +/- ##
=======================================
Coverage 91.67% 91.68%
=======================================
Files 113 113
Lines 44419 44467 +48
=======================================
+ Hits 40721 40768 +47
- Misses 3698 3699 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mcollina
requested review from
Uzlopak and
ronag
and removed request for
ronag
November 6, 2026 10:18
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 is the undici counterpart of nodejs/node#67292.
Problem
The keep-alive timer of an idle HTTP/1.1 socket cannot fire while the event loop is blocked. Before reusing an idle socket, undici yields one
setImmediate(scheduleIdleSocketValidation, added for GHSA-35p6-xmwp-9g52), so that a FIN or RST that has already been received is processed first. That only works if a poll phase runs between the dispatch and the check phase.With a server in a separate process (
keepAliveTimeout = 5000), one request, then a 6s synchronous block, then a second request:mainawaitafter I/O)ECONNRESET: the dead socket is reusedsetImmediate)The poll-phase case is the common one, for example a proxy that does synchronous work in its request handler before calling upstream. A shorter version of the same problem: a block longer than the client's keep-alive timeout but shorter than the server's uses up the
keepAliveTimeoutThresholdmargin, and the request is sent just before the server closes the connection.Fix
resumeH1arms the keep-alive timer, recordperformance.now()on the socket.InformationalError('socket idle timeout')if its keep-alive timeout has passed. Nothing is running on the socket, so the pending requests are sent on a new connection, the same as when the timer fires.The time is recorded when the timer is armed, so the check never expires a socket before the timer would have. It uses the global
performance.now(), so it follows@sinonjs/fake-timerstogether withsetTimeout. The cost is oneperformance.now()call when a socket becomes idle and one when it is reused.The check does not depend on
kSocketUsed, so it also covers the experimental Milo parser.parser-h1.jsnever sets that symbol, which is private toclient-h1.js. As a result, the existing idle socket validation does not run with Milo. That is a separate issue and is left for a follow-up.Not covered
As in the Node.js change:
HTTP/2 is not changed.
Testing
test/client-keep-alive-blocked-loop.jsblocks inside anfscallback (poll phase) and checks that an expired socket is replaced and that a socket that has not expired is reused. The expiry case fails onmainand passes with this change, with both llhttp andUNDICI_USE_MILO=1.test/*.js: 1664 passed, 0 failed, 3 skipped.test/node-test/**: 245 passed, 0 failed, 5 skipped.🤖 Generated with Claude Code
https://claude.ai/code/session_01Sfj4nEWQ4ovycNDjbvXcRs