fix(h2): deliver an early final response to an Expect: 100-continue request#5470
Open
jeswr wants to merge 1 commit into
Open
fix(h2): deliver an early final response to an Expect: 100-continue request#5470jeswr wants to merge 1 commit into
jeswr wants to merge 1 commit into
Conversation
…equest Over HTTP/2, when a server answered a request carrying Expect: 100-continue with a final response instead of 100 (Continue), the body write stayed bound to the never-fired 'continue' event: the client never sent END_STREAM, the stream stayed half-open, its 'close' never fired, and the response was never delivered (the request hung). When a final response arrives before the body has been sent, close the request stream's writable half so the stream completes and the response is delivered, without sending the body (RFC 9110 Section 10.1.1 allows the early response). Refs: nodejs#5465 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jun 30, 2026
Closed
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5470 +/- ##
=======================================
Coverage 93.46% 93.46%
=======================================
Files 110 110
Lines 37115 37124 +9
=======================================
+ Hits 34690 34699 +9
Misses 2425 2425 ☔ View full report in Codecov by Harness. 🚀 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.
Fixes #5465.
Problem
Over HTTP/2, when a server answers a request carrying
Expect: 100-continuewith a final response (e.g.401) instead of100 (Continue), undici withholds the request body correctly but never delivers the response — the request hangs.The body write is bound to the stream's
'continue'event; on an early final response that never fires, so the client never sendsEND_STREAM. The h2 stream stays half-open, its'close'never fires, andonRequestStreamClose(which finalizes the response) never runs. RFC 9110 §10.1.1 permits a server to answer with a final status determinable from the header fields in place of100 (Continue), so this is a client conformance bug. HTTP/2 only — HTTP/1.x already handles it.Fix
In
onResponse(lib/dispatcher/client-h2.js): when a final response arrives and the body was never sent, remove thecontinuelistener andstream.end()the writable half, so the stream completes and the response is delivered without sending the body. "Body not sent" is tracked with a newstate.bodySent, set whenwriteBodyH2runs.Tests
New case in
test/http2-continue.js: an early401to anExpect: 100-continuePOSTis delivered, and the server receives 0 body bytes. The existing h2 suite passes.Minimal reproduction: https://github.com/jeswr/undici-h2-expect-continue-bug