Repository navigation
fix(mux-h2): send the advisory GOAWAY even while a peer header block is incomplete - #1649
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 28, 2026 05:43
FlorentinDUBOIS
force-pushed
the
fix/h2-goaway-mid-header-block
branch
3 times, most recently
from
September 28, 2026 07:59
c3d6999 to
dbc7e25
Compare
…is incomplete A graceful drain deferred its initial GOAWAY(NO_ERROR, 2^31-1) while a HEADERS/CONTINUATION block was being reassembled. The deferral was added for #1401, when the GOAWAY was serialised into zero.storage, the buffer that also held the block. Since #1625 control frames go to the separate output queue and the block lives in ConnectionH2::header_reassembly, so the deferral protected no buffer. It still had an effect on the wire: when a soft-stop landed while a connection's only stream was mid-block, that stream was still Idle, Mux::shutting_down_inner did not wait for it, nothing was queued, and the session closed with no GOAWAY at all, against RFC 9113 §6.8. RFC 9113 §4.3/§6.10 constrain the sender of a field block, not a GOAWAY travelling the other way; hyperium/h2 (Connection::go_away_gracefully) and HAProxy (h2_process) send it unconditionally too. Remove the deferral: H2DrainState::initial_goaway_pending, GracefulDrainDecision::DeferInitial, take_deferred_initial_goaway and its test accessor, the reassembly_in_progress parameter of begin_graceful_drain, the deferred-GOAWAY stage of flush_pending_control_frames, the DeferInitial arm of graceful_goaway, and header_block_reassembly_in_progress, which has no caller left. test_h2_graceful_drain_mid_header_block_sends_goaway_before_closing pins the wire behaviour: red before (0 bytes, no GOAWAY before the close), green after. a_legitimate_continuation_survives_a_graceful_goaway now reads the advisory GOAWAY on the peer socket before the CONTINUATION is sent, then checks the block still decodes. The h2_drain unit tests that asserted the flag are replaced by tests of the remaining decisions. Docs: h2_drain.rs module doc, LIFECYCLE.md §2.2 and invariant 24, doc/h2_mux_internals.md, the sozu#1453 paragraph of doc/testing.md, the e2e test's doc comment and CHANGELOG. Prose citations the removal shifted now name a symbol; pinned code-block annotations, which quote their lines verbatim, are re-pointed. Closes #1637 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/h2-goaway-mid-header-block
branch
from
September 28, 2026 09:08
dbc7e25 to
0664483
Compare
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.
Summary
A graceful drain deferred its advisory
GOAWAY(NO_ERROR, 2^31-1)while a peer HEADERS/CONTINUATION block was being reassembled (GracefulDrainDecision::DeferInitial, added for #1401 when the GOAWAY was serialised intozero.storage, the buffer that also held the block). Since #1625 control frames go to the separate output queue and the block lives inConnectionH2::header_reassembly, so the deferral protected no buffer. #1637 found that the e2e test built for it (sozu#1453) no longer notices the mutationDeferInitial → SendInitial.Re-running that mutation against the wire showed the deferral still had one effect, and a harmful one: a soft-stop landing while a connection's only stream is mid-block closes the session with no GOAWAY at all. That stream is still
StreamState::Idle,Mux::shutting_down_inner(lib/src/protocol/mux/mod.rs) does not wait for it, and with the GOAWAY deferred nothing is queued. This violates RFC 9113 §6.8: "Endpoints SHOULD always send a GOAWAY frame before closing a connection".The deferral has no protocol basis:
Connection::go_away_gracefully(src/proto/connection.rs) sends it at once, never consultingFramedRead::partial.h2_process(src/mux_h2.c@0ceb8c65f) sends it onPR_FL_STOPPEDwithout looking at the demux state.This PR removes the deferral. Behaviour change: the advisory GOAWAY now leaves in the drain pass itself, possibly before the rest of a peer's header block, and a session no longer closes mid-block without one.
Closes #1637
Removed
H2DrainState::initial_goaway_pending,GracefulDrainDecision::DeferInitial,H2DrainState::take_deferred_initial_goaway,H2DrainState::__test_initial_goaway_pending(lib/src/protocol/mux/h2_drain.rs)reassembly_in_progressparameter ofH2DrainState::begin_graceful_drainConnectionH2::flush_pending_control_framesand theDeferInitialarm ofConnectionH2::graceful_goaway(lib/src/protocol/mux/h2.rs)ConnectionH2::header_block_reassembly_in_progress, which has no caller leftRed → green
New e2e test
test_h2_graceful_drain_mid_header_block_sends_goaway_before_closing(e2e/src/tests/h2_tests.rs). It sends half a HEADERS block (no END_HEADERS) and waits onh2.frames.rx.headers(no timer) before callingsoft_stop(). Afterwait_for_server_stop()it reads everything that reached the client and requires aGOAWAY(NO_ERROR).On
a3cb11ae(before the change),unshare -rn,--exact:The same shape measured with a scratch test before this change: 4/4 runs
bytes=0 goaway=falseonmain, and 3/3 runsGOAWAY error_code=0x0, bytes=17with theDeferInitial → SendInitialmutation.After this change:
test result: ok. 1 passed.Tests modified
h2::tests::a_legitimate_continuation_survives_a_graceful_goaway(h2.rs): it asserted the internal flag (__test_initial_goaway_pending()true, then false afterwritable()). It now reads the 17-byteGOAWAY(NO_ERROR, STREAM_ID_MAX)on the peer socket before sending the CONTINUATION, and keeps every decode assertion (block decodes byte-for-byte, peer dynamic table still resolves). It also asserts thatgraceful_goawayleavesH2State::ContinuationHeaderuntouched, and that completing the block queues no second GOAWAY. Seen red with the deferral reintroduced ingraceful_goaway:the peer must receive the advisory GOAWAY before it completes the block: WouldBlock.h2_drain::tests::initial_state: dropped the flag assertion (the field no longer exists).h2_drain::tests::begin_graceful_drain_sends_initial_when_no_reassembly→begin_graceful_drain_sends_the_initial_goaway_on_the_first_call: same assertions minus the flag; the decision no longer takes a reassembly input.h2_drain::tests::begin_graceful_drain_defers_initial_during_reassembly: removed. It asserted the removed decision; the wire behaviour it stood for is now asserted by the two tests above.h2_drain::tests::take_deferred_initial_goaway_only_fires_when_ready: removed together with the method it tested.h2_drain::tests::enter_final_goaway_supersedes_a_deferred_initial_goaway→enter_final_goaway_after_a_graceful_drain_keeps_the_budget_armed: there is no deferred GOAWAY left to supersede. It now pins that the final GOAWAY neither arms nor moves the forced-close budget, whichenter_final_goawayalso asserts as a newdebug_assert_eq!.h2_drain::tests::enter_final_goaway_marks_draining_even_without_a_prior_graceful_drain: added thestarted_at == Noneassertion.h2_drain::tests::begin_graceful_drain_is_idempotent_and_does_not_rearm_the_budget,deadline_elapsed_respects_configured_budget,deadline_elapsed_never_fires_when_deadline_is_none: call sites only (one argument fewer).reassembly_property(h2.rs): interleave variantGracefulGoawayDeferrenamedGracefulGoaway, because it no longer defers. Behaviour unchanged, property green.test_h2_continuation_survives_a_graceful_drain_mid_reassembly(e2e): doc comment and inline comments only. They described the GOAWAY as deliberately deferred. The corruption anddrain_witnessedassertions are unchanged.Docs
h2_drain.rsmodule doc: the dual-role-hazard section is replaced by the history and the reason for removal.doc/h2_mux_internals.md: theflush_pending_control_framesstage list, and the field list ofH2DrainState.doc/testing.md: the sozu#1453 paragraph is now also the example of a guard made inert by a refactor and revealed by re-running its mutation.h2_header_reassembly.rsmodule doc.Removing ~80 lines from
h2.rsshifted 31file:NNNcitations indoc/andLIFECYCLE.md. They are re-pointed through a diff-based line mapping, and one that had already drifted onmain(h2.rs:5294) now cites a symbol.A distinct defect found here, out of scope: #1647. A stream still in reassembly does not hold the drain open, so its request is lost and no final GOAWAY with the real
last_stream_idis sent.Commands run (after rebase on
96b4bca9)cargo +nightly fmt --all -- --check→ 0cargo build --locked→ 0;cargo build --all-features --locked→ 0cargo clippy --all-targets --locked -- -D warnings→ 0cargo clippy --all-targets --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd -- -D warnings→ 0cargo test --workspace --locked -- --skip tests::fuzz_tests:: --test-threads=8→ 2198 passed, 0 failed, 14 ignoredRUSTFLAGS="--cfg tokio_unstable" cargo test -p sozu-sim --locked→ 0RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked→ 0check_doc_citations.py:--self-test0, broken fixture 1 (expected),--base origin/main0, plain 0unshare -rnwithloup, one e2e process,--exact:test_h2_graceful_drain_mid_header_block_sends_goaway_before_closing10/10test_h2_continuation_survives_a_graceful_drain_mid_reassembly10/10git merge-tree --write-tree origin/main HEADcleanSigned-off-by: Florentin Dubois [email protected]