fix(h2): honour headersTimeout - #5604
Merged
Merged
Conversation
writeH2() armed the stream timer from bodyTimeout for the whole request:
const requestTimeout = request.bodyTimeout ?? client[kBodyTimeout]
so headersTimeout had no effect at all over HTTP/2. A server that accepted
the stream and never sent headers was only cut off after bodyTimeout — with
headersTimeout: 200 and bodyTimeout: 5000 the request failed after 5131ms
instead of ~200ms.
Arm the timer with headersTimeout, switch it to bodyTimeout once the
response headers arrive, and report whichever deadline actually elapsed as
HeadersTimeoutError or BodyTimeoutError instead of a generic
InformationalError, matching the HTTP/1.1 path.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A49JamgF2TkZHu5h58ChUM
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 @@
## v7.x #5604 +/- ##
==========================================
- Coverage 93.17% 93.15% -0.02%
==========================================
Files 112 112
Lines 36751 36760 +9
==========================================
+ Hits 34241 34245 +4
- Misses 2510 2515 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ronag
approved these changes
Jul 29, 2026
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.
writeH2()armed the stream timer frombodyTimeoutfor the whole request:so
headersTimeouthad no effect at all over HTTP/2. A server that accepted the stream and never sent headers was only cut off afterbodyTimeout.With
headersTimeout: 200, bodyTimeout: 5000against a server that accepts the stream and never responds:InformationalError: HTTP/2: "stream timeout after 5000"HeadersTimeoutError: HTTP/2: "headers timeout after 200"Change
headersTimeoutbodyTimeoutonce the response headers arriveHeadersTimeoutError(UND_ERR_HEADERS_TIMEOUT) orBodyTimeoutError(UND_ERR_BODY_TIMEOUT), matching the HTTP/1.1 path andmainThe upgrade / CONNECT paths also use
headersTimeout, since those streams are waiting for a response.Behaviour changes worth a look
Two, both on the h2 path only:
headersTimeout < bodyTimeout— that is the point of the fix, but anyone who had (unknowingly) been relying onbodyTimeoutcovering the headers phase will see requests fail sooner. The defaults are equal (300s), so only users who set the two differently are affected.UND_ERR_INFO/"stream timeout after N"becomesUND_ERR_HEADERS_TIMEOUT/UND_ERR_BODY_TIMEOUTwith"headers timeout after N"/"body timeout after N". This aligns v7 with h1 and withmain, so it removes a surprise on upgrade, but it is a visible change for anyone matching on the old code or string.test/http2-timeout.jsis updated accordingly.Happy to drop (2) and keep the
InformationalErrorshape if you would rather not change error codes on a maintenance branch — the timing fix stands on its own.Tests
test/http2-headers-timeout.jscovers both directions:headersTimeoutfiring whilebodyTimeoutis much larger, andbodyTimeoutapplying once headers have arrived. Both were verified to fail before this change (the first waiting 5131ms and reporting the wrong error).test/+(http2|h2)*.js: 52 pass. Full unit suite: 1305 pass, 0 fail.🤖 Generated with Claude Code
https://claude.ai/code/session_01A49JamgF2TkZHu5h58ChUM