Skip to content

fix(h2): deliver an early final response to an Expect: 100-continue request#5470

Open
jeswr wants to merge 1 commit into
nodejs:mainfrom
jeswr:fix/h2-expect-continue-early-response
Open

fix(h2): deliver an early final response to an Expect: 100-continue request#5470
jeswr wants to merge 1 commit into
nodejs:mainfrom
jeswr:fix/h2-expect-continue-early-response

Conversation

@jeswr

@jeswr jeswr commented Jun 30, 2026

Copy link
Copy Markdown

Fixes #5465.

Problem

Over HTTP/2, when a server answers a request carrying Expect: 100-continue with a final response (e.g. 401) instead of 100 (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 sends END_STREAM. The h2 stream stays half-open, its 'close' never fires, and onRequestStreamClose (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 of 100 (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 the continue listener and stream.end() the writable half, so the stream completes and the response is delivered without sending the body. "Body not sent" is tracked with a new state.bodySent, set when writeBodyH2 runs.

Tests

New case in test/http2-continue.js: an early 401 to an Expect: 100-continue POST is delivered, and the server receives 0 body bytes. The existing h2 suite passes.

Minimal reproduction: https://github.com/jeswr/undici-h2-expect-continue-bug

…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>

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.46%. Comparing base (907bc33) to head (1c82ecf).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollina mcollina requested review from metcoder95 and trivikr June 30, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP/2: request hangs when the server sends a final response to an Expect: 100-continue request

3 participants