Repository navigation
Description
Summary
A soft-stop that lands while an H2 connection's only stream is still receiving its HEADERS/CONTINUATION field block closes the session in the same drain pass. The request is lost, and the client never receives a final GOAWAY carrying the real last_stream_id, so it cannot tell whether that stream was processed.
Mechanism
ConnectionH2::handle_header_state(lib/src/protocol/mux/h2.rs) creates the stream viaConnectionH2::create_streamwhen the HEADERS frame header arrives, andConnectionH2::handle_headers_frameparks the connection inH2State::ContinuationHeaderwhile END_HEADERS is unset. The stream staysStreamState::Idle(Stream::new,lib/src/protocol/mux/stream.rs) until the block completes and is routed.Mux::shutting_down_inner(lib/src/protocol/mux/mod.rs) setscan_stop = falseonly forStreamState::Linked(_)and non-quiescedStreamState::Unlinkedstreams. AnIdlestream mid-reassembly does not hold the session open.- Once
graceful_goawayhas queued and flushed the advisoryGOAWAY(NO_ERROR, 2^31-1),Connection::has_pending_writeis false,shutting_down_innerreturnstrue, andServer::shut_down_sessions(lib/src/server.rs) closes the session. - The final GOAWAY (the
AlreadyDrainingarm ofConnectionH2::graceful_goaway, i.e.ConnectionH2::goaway(H2Error::NoError)withH2StreamTable::highest_peer_stream_id) is never sent on this path.
Scenario
- Client opens an H2 connection and sends
HEADERSfor stream 1 without END_HEADERS (a large request header block split across frames, or a slow client). - The worker receives a soft stop before the CONTINUATION arrives.
- The client receives the advisory GOAWAY (last_stream_id = 2^31-1) and then the connection closes. Its request is not served, and nothing tells it the request was not processed.
test_h2_graceful_drain_mid_header_block_sends_goaway_before_closing (e2e/src/tests/h2_tests.rs) reproduces the shape. It asserts only that a GOAWAY precedes the close, which #1637 fixed.
Why it matters
RFC 9113 §6.8: "Endpoints SHOULD always send a GOAWAY frame before closing a connection so that the remote peer can know whether a stream has been partially processed or not." The advisory GOAWAY at 2^31-1 claims nothing about which streams were processed. §6.8 also describes the graceful sequence: initial GOAWAY at 2^31-1, then, "after allowing time for any in-flight stream creation (at least one round-trip time)", a GOAWAY with the updated last stream identifier. Here the in-flight stream is neither given that time nor reported.
Possible directions (not decided)
- Treat a stream whose header block is still being reassembled (
H2State::ContinuationHeader/ContinuationFrameon the frontend) as keeping the session alive inMux::shutting_down_inner, bounded by the existingh2_graceful_shutdown_deadline_secondsforced-close budget. - Or, when closing a draining session, send the final GOAWAY with the real
last_stream_idfirst (excluding the incomplete stream), so the client knows it may retry.
Found while working on #1637; out of that change's scope.
Activity
fix(mux-h2): send the advisory GOAWAY even while a peer header block …
fix(mux-h2): wait for an incomplete header block on soft-stop and clo…
fix(mux-h2): wait for an incomplete header block on soft-stop and clo…
docs: document the hot-path zero-copy and syscall campaign and refres…
docs: document the hot-path zero-copy and syscall campaign and refres…
docs: document the hot-path zero-copy and syscall campaign and refres…
fix(mux-h2): wait for an incomplete header block on soft-stop and clo…