Skip to content

fix(mux-h2): send the advisory GOAWAY even while a peer header block is incomplete - #1649

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/h2-goaway-mid-header-block
Sep 28, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/h2-goaway-mid-header-block

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

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 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. #1637 found that the e2e test built for it (sozu#1453) no longer notices the mutation DeferInitial → 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:

  • RFC 9113 §4.3 ("Field blocks MUST be transmitted as a contiguous sequence of frames") and §6.10 constrain the sender of a field block, here the client. A GOAWAY travelling the other way interleaves nothing.
  • §6.8's "SHOULD send an initial GOAWAY frame with the last stream identifier set to 2^31-1" is not conditioned on the peer's state.
  • hyperium/h2 0.4.19: Connection::go_away_gracefully (src/proto/connection.rs) sends it at once, never consulting FramedRead::partial.
  • HAProxy h2_process (src/mux_h2.c @ 0ceb8c65f) sends it on PR_FL_STOPPED without 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)
  • the reassembly_in_progress parameter of H2DrainState::begin_graceful_drain
  • the deferred-GOAWAY stage of ConnectionH2::flush_pending_control_frames and the DeferInitial arm of ConnectionH2::graceful_goaway (lib/src/protocol/mux/h2.rs)
  • ConnectionH2::header_block_reassembly_in_progress, which has no caller left

Red → 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 on h2.frames.rx.headers (no timer) before calling soft_stop(). After wait_for_server_stop() it reads everything that reached the client and requires a GOAWAY(NO_ERROR).

On a3cb11ae (before the change), unshare -rn, --exact:

H2 drain mid-block - received 0 frames
H2 drain mid-block - the session closed without a GOAWAY(NO_ERROR) (0 bytes received, stopped=true)
stability check FAILED: iteration 1 of 1 did not succeed (a single clean run is required)
test result: FAILED. 0 passed; 1 failed

The same shape measured with a scratch test before this change: 4/4 runs bytes=0 goaway=false on main, and 3/3 runs GOAWAY error_code=0x0, bytes=17 with the DeferInitial → SendInitial mutation.

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 after writable()). It now reads the 17-byte GOAWAY(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 that graceful_goaway leaves H2State::ContinuationHeader untouched, and that completing the block queues no second GOAWAY. Seen red with the deferral reintroduced in graceful_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, which enter_final_goaway also asserts as a new debug_assert_eq!.
  • h2_drain::tests::enter_final_goaway_marks_draining_even_without_a_prior_graceful_drain: added the started_at == None assertion.
  • 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 variant GracefulGoawayDefer renamed GracefulGoaway, 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 and drain_witnessed assertions are unchanged.

Docs

  • h2_drain.rs module doc: the dual-role-hazard section is replaced by the history and the reason for removal.
  • LIFECYCLE.md §2.2 and invariant 24.
  • doc/h2_mux_internals.md: the flush_pending_control_frames stage list, and the field list of H2DrainState.
  • 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.rs module doc.
  • CHANGELOG (Fixed).

Removing ~80 lines from h2.rs shifted 31 file:NNN citations in doc/ and LIFECYCLE.md. They are re-pointed through a diff-based line mapping, and one that had already drifted on main (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_id is sent.

Commands run (after rebase on 96b4bca9)

  • cargo +nightly fmt --all -- --check → 0
  • cargo build --locked → 0; cargo build --all-features --locked → 0
  • cargo clippy --all-targets --locked -- -D warnings → 0
  • cargo clippy --all-targets --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd -- -D warnings → 0
  • cargo test --workspace --locked -- --skip tests::fuzz_tests:: --test-threads=8 → 2198 passed, 0 failed, 14 ignored
  • RUSTFLAGS="--cfg tokio_unstable" cargo test -p sozu-sim --locked → 0
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked → 0
  • check_doc_citations.py: --self-test 0, broken fixture 1 (expected), --base origin/main 0, plain 0
  • Stability, 10 sequential runs each, unshare -rn with lo up, one e2e process, --exact:
    • test_h2_graceful_drain_mid_header_block_sends_goaway_before_closing 10/10
    • test_h2_continuation_survives_a_graceful_drain_mid_reassembly 10/10
  • git merge-tree --write-tree origin/main HEAD clean

Signed-off-by: Florentin Dubois [email protected]

@FlorentinDUBOIS
FlorentinDUBOIS force-pushed the fix/h2-goaway-mid-header-block branch 3 times, most recently from c3d6999 to dbc7e25 Compare September 28, 2026 07:59
…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
FlorentinDUBOIS force-pushed the fix/h2-goaway-mid-header-block branch from dbc7e25 to 0664483 Compare September 28, 2026 09:08
@FlorentinDUBOIS
FlorentinDUBOIS merged commit ca42a2e into main Sep 28, 2026
5 of 22 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the fix/h2-goaway-mid-header-block branch September 28, 2026 09:10
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.

e2e: the CONTINUATION drain test no longer detects a forced SendInitial since #1625

1 participant