Repository navigation
fix(mux-h2): cap enqueue_rst per insert so a mass reap cannot grow the pending RST queue past its bound - #1434
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 22, 2026 08:49
FlorentinDUBOIS
force-pushed
the
fix/h2-enqueue-rst-cap
branch
5 times, most recently
from
September 23, 2026 00:16
1e474f8 to
31626a4
Compare
enqueue_rst_into had no per-insert cap. The only bound was flush_pending_control_frames' total_rst_streams_queued >= MAX_PENDING_RST_STREAMS short-circuit, which runs before the drain loop: it bounds what is written and says nothing about how large the queue got before anyone looked. handle_frame runs check_invariants after each dispatch, so the enqueue_rst calls reached through it are inspected between inserts. It is also the only production caller of check_invariants, and two insert paths never reach it. cancel_timed_out_streams is the larger one: it walks the entire timed-out set and calls enqueue_rst for every entry in one sweep - an unbounded number of inserts between two checks - deliberately discarding the flood-violation signal each call returns, and from Mux::timeout it runs when handle_frame does not run at all. The DATA-on-closed-stream reset is the other: it sits in handle_header_state, which readable returns into directly on a branch that never reaches handle_frame. That second path is separately rate-limited - record_glitch + check_flood_or_return! cap it at DEFAULT_MAX_GLITCH_COUNT (100) inside one flood window, and the window can only half-decay when Mux::ready_inner resamples context.now on a new outer iteration, which is strictly after an inner iteration that already ran writable() - so it cannot fill the queue by itself; its inserts are simply not inspected either. With max_concurrent_streams raised above 200 (operator-settable up to MAX_SAFE_CONCURRENT_STREAMS = 10 000) and enough streams idling or window-stalling into the same sweep, pending_rst_streams.len() passed the <= MAX_PENDING_RST_STREAMS + 1 bound invariant 3 asserts: a debug build panicked on the next inbound frame, a release build grew the queue unbounded. That setting bounds the live set one sweep walks, not the queue, which holds what every caller queued since the last successful drain. The reaper is reached from readable(), where a later handle_frame trips the assertion, and from Mux::timeout, where - against the fully silent peer that produces a mass reap - handle_frame never runs at all. enqueue_rst_into now takes max_pending and returns an EnqueueRstOutcome (Queued / Deduped / Dropped), mirroring H2FlowControl::queue_window_update's max_pending-gated QueueWindowUpdateOutcome::Dropped. At capacity it queues nothing, bumps no counter, records nothing in rst_sent - the cap is tested before the dedupe insert, so an id is never marked reset without its frame being queued - and does not re-arm WRITABLE. enqueue_rst answers with the new h2.rst_stream_dropped counter and a session-context error! line, the drop + metric + log shape h2.window_update_dropped already uses for the sibling control queue. No RST that would have reached the wire is lost, and the peer is not left believing a refused stream is live. Invariant 3 keeps total_rst_streams_queued >= pending_rst_streams.len(), so a full queue implies total_rst_streams_queued >= MAX_PENDING_RST_STREAMS - the counter half of the condition flush_pending_control_frames tests before draining, where it emits GOAWAY(ENHANCE_YOUR_CALM) (RFC 9113 6.8, the documented answer to RST_STREAM abuse since CVE-2023-44487) and the connection is torn down instead. The other half is a state gate, !matches!(self.state, H2State::GoAway | H2State::Error), which the RST drain beneath it does not share: goaway() enters H2State::GoAway without clearing pending_rst_streams, so a Mux::timeout reap landing after the first GOAWAY is dropped with no second escalation while the drain still serialises what is queued. That window is bounded and benign - the peer already holds the GOAWAY that made the connection terminal, and writable()'s GoAway arm force-disconnects on the same pass. The 200 enqueues that filled the queue each armed WRITABLE, so the escalation runs on the next writable tick on both reaper call paths. No new GOAWAY site is added: raising one from enqueue_rst would re-enter goaway() once per remaining reaped stream, clobbering zero.storage and inflating h2.goaway.sent.*. Seen red, with the `pending.len() >= max_pending` guard deleted from the top of enqueue_rst_into: $ cargo test -p sozu-lib --locked mass_reap ---- protocol::mux::h2::tests:: mass_reap_keeps_the_pending_rst_queue_within_its_hard_cap stdout ---- panicked at lib/src/protocol/mux/h2.rs:4650:9: pending RST queue must stay within its hard cap (escalates at the cap) test result: FAILED. 0 passed; 1 failed; [exit 101] That message is check_invariants invariant 3; 4650 is its line in the mutated tree. The same mutation makes $ cargo test -p sozu-lib --locked prop_pending_rst_queue_stays_within_its_bound panicked at quickcheck-1.1.0/src/tester.rs:182:28: [quickcheck] TEST FAILED. Arguments: ([Reap(118)]) [exit 101] Moving the guard below rst_sent.insert instead makes $ cargo test -p sozu-lib --locked \ test_enqueue_rst_into_refuses_at_capacity_without_side_effects panicked at lib/src/protocol/mux/h2.rs:8190:9: an at-capacity refusal must not record the id as reset [exit 101] Each test doc-comment now carries the command that reproduces its own red. Covered by those three plus the four other test_enqueue_rst_into_* unit tests. Also relocates the LIFECYCLE.md and doc/testing.md h2.rs line citations this changeset shifted, mechanically mapped by exact line text against the branch base and spot-verified; the fc-stall arm site is re-anchored on its arm_fc_stall call. .github/scripts/check_doc_citations.py --base origin/main passes. Closes #1413 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/h2-enqueue-rst-cap
branch
from
September 23, 2026 00:25
31626a4 to
862c195
Compare
This was referenced Sep 23, 2026
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 26, 2026
…sts in CI snapshot_h2_120x40 has failed under `cargo test -p sozu --features tui` since #1434, which added the h2.rst_stream_dropped row to the H2 pane's flood table (bin/src/ctl/top/panes/h2.rs) without updating the stored insta snapshot: $ cargo test -p sozu --features tui test ctl::top::snapshot_tests::snapshot_h2_120x40 ... FAILED +││rst_stream_dropped 0 — ││ test result: FAILED. 134 passed; 1 failed [exit 101] The row itself is intended: #1434 gives the RST_STREAM control queue the same drop + metric + log shape h2.window_update_dropped already has, and the pane lists both. Its trend cell is not: it printed `—` where every sibling row draws a sparkline, because #1434 did not add the key to H2_TRACKED_KEYS (bin/src/ctl/top/app.rs), the list App::fold_h2_trends samples, whose own doc-comment says it exists so a key cannot silently lose its sparkline. Accepting the snapshot as rendered would have frozen that gap. The key is now tracked beside WINDOW_UPDATE_DROPPED, and the snapshot is regenerated with INSTA_UPDATE=always to the corrected frame: the new row with a `▁▁` trend, one fewer blank line below it. Seen red with only the H2_TRACKED_KEYS line removed: $ cargo test -p sozu --features tui --lib snapshot_h2 -││rst_stream_dropped 0 ▁▁ ││ +││rst_stream_dropped 0 — ││ test result: FAILED. 0 passed; 1 failed [exit 101] No other snapshot was stale: the full tui suite passes, 135 tests. The drift went unnoticed because no CI cell enables `tui`, so `Test sozu` compiles every `top` unit test out. A new step on the msrv-full cell runs `cargo test -p sozu --features tui --lib`: that cell already resolves the tui dependencies for `cargo doc --all-features`, nothing in `top` varies by crypto provider, and `--lib` bounds the cost to one extra build of the sozu library test binary (41 s locally with warm dependencies). The sozu_top_e2e step proposed separately in #1575 is left to that PR. Closes #1576 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 26, 2026
…sts in CI snapshot_h2_120x40 has failed under `cargo test -p sozu --features tui` since #1434, which added the h2.rst_stream_dropped row to the H2 pane's flood table (bin/src/ctl/top/panes/h2.rs) without updating the stored insta snapshot: $ cargo test -p sozu --features tui test ctl::top::snapshot_tests::snapshot_h2_120x40 ... FAILED +││rst_stream_dropped 0 — ││ test result: FAILED. 134 passed; 1 failed [exit 101] The row itself is intended: #1434 gives the RST_STREAM control queue the same drop + metric + log shape h2.window_update_dropped already has, and the pane lists both. Its trend cell is not: it printed `—` where every sibling row draws a sparkline, because #1434 did not add the key to H2_TRACKED_KEYS (bin/src/ctl/top/app.rs), the list App::fold_h2_trends samples, whose own doc-comment says it exists so a key cannot silently lose its sparkline. Accepting the snapshot as rendered would have frozen that gap. The key is now tracked beside WINDOW_UPDATE_DROPPED, and the snapshot is regenerated with INSTA_UPDATE=always to the corrected frame: the new row with a `▁▁` trend, one fewer blank line below it. Seen red with only the H2_TRACKED_KEYS line removed: $ cargo test -p sozu --features tui --lib snapshot_h2 -││rst_stream_dropped 0 ▁▁ ││ +││rst_stream_dropped 0 — ││ test result: FAILED. 0 passed; 1 failed [exit 101] No other snapshot was stale: the full tui suite passes, 135 tests. The drift went unnoticed because no CI cell enables `tui`, so `Test sozu` compiles every `top` unit test out. A new step on the msrv-full cell runs `cargo test -p sozu --features tui --lib`: that cell already resolves the tui dependencies for `cargo doc --all-features`, nothing in `top` varies by crypto provider, and `--lib` bounds the cost to one extra build of the sozu library test binary (41 s locally with warm dependencies). The sozu_top_e2e step proposed separately in #1575 is left to that PR. Closes #1576 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 26, 2026
…#1575) Closes #1574 ## Cause `sozu top --snapshot N` is documented in `bin/src/cli.rs` as a "test affordance, no terminal control", but `render::run` installed `RawModeGuard` unconditionally (`bin/src/ctl/top/render.rs`, `let _guard = RawModeGuard::install(cfg.mouse)?;`). Its `enable_raw_mode()` reaches crossterm 0.29's `tty_fd()`, which opens `/dev/tty` when stdin is not a terminal. Without a controlling terminal that open fails with ENXIO, and `ctl/top/mod.rs` wraps it as `ResolvePath("sozu top render loop", … os error 6)`. Removing the guard alone would not be enough: `event::poll` lazily builds crossterm's event source, which calls `tty_fd()` too, and `Terminal::new` (a fullscreen viewport) asks the backend for the terminal size. ## Fix Only when `--snapshot` is set, `render::run` now: - enters neither raw mode nor the alternate screen, and captures no mouse (no `RawModeGuard`); - installs no terminal-restoring panic hook, since there is nothing to restore; - reads no input: the loop sleeps for its pacing interval instead of calling `poll`/`read`; - draws into a fixed 80x24 `Viewport::Fixed`, which ratatui 0.30 neither sizes from nor resizes to the terminal (`Terminal::with_options` and `autoresize` both skip `backend.size()` for a fixed viewport). 80x24 is the smaller of the two sizes the `insta` tests render every pane at. Frames go to stdout as ANSI escape sequences. Interactive mode and `--tick-once` are unchanged. ## CI `sozu_top_e2e` now passes without a pty, so a new step runs it on the `msrv-full` cell only. That cell already resolves the `tui` feature for `cargo doc --all-features`, so the added cost is one build of the `sozu` binary with `tui`, once per pipeline. The step also runs the two non-ignored `sozu top` tests, which no cell ran before. The `.github/workflows/ci.yml` comment that kept the test out, the test's doc comment, and the last sentence of #1573's CHANGELOG entry now say it runs. ## Verification Run outside a pty (`tty` reports "not a tty"): - before the fix: `cargo test -p sozu --features tui --test sozu_top_e2e -- --include-ignored` exits 101, `sozu_top_tick_once_against_real_master` fails with `could not resolve path for sozu top render loop : No such device or address (os error 6)`; - after the fix, the same command: exit 0, 3 passed. The new CI step's command, `cargo test -p sozu --locked --features opentelemetry,splice,simd --features tui --test sozu_top_e2e -- --include-ignored`, run with stdin at `/dev/null`: exit 0, 3 passed; - `cargo build`, `cargo clippy --all-targets -D warnings` (`crypto-ring,opentelemetry,splice,simd`, and `-p sozu --features tui`), `cargo +nightly fmt --check`, `cargo test -p sozu` (ring features, 226 passed), the three other `bin/tests/*_e2e` with `--ignored`, `cargo test -p sozu-command-lib` (184 passed), the four `check_doc_citations.py` invocations and `RUSTDOCFLAGS="-D warnings" cargo doc --all-features`: all exit 0. ## Out of scope - `cargo test -p sozu --features tui` fails on `snapshot_h2_120x40`: the H2 pane now lists `rst_stream_dropped` (since #1434) but the `.snap` file does not. It fails identically with this PR's `render.rs` reverted, `origin/main`'s snapshot lacks the row too, and no CI cell runs that suite. - The e2e takes about 30 s both before and after this change. It already did when the render loop failed on its first call, so the time is spent outside the loop; its cause was not investigated here. Signed-off-by: Florentin Dubois <[email protected]>
pull Bot
pushed a commit
to jrcribb/sozu
that referenced
this pull request
Sep 26, 2026
…sts in CI (sozu-proxy#1577) `snapshot_h2_120x40` fails on `main` under `cargo test -p sozu --features tui` since sozu-proxy#1434 added the `h2.rst_stream_dropped` row to the H2 pane without updating the stored insta snapshot. ## Why not just accept the snapshot The row is intended: sozu-proxy#1434 gives the RST_STREAM control queue the same drop + metric + log shape as `h2.window_update_dropped`, and the pane lists both. Its trend cell was not: it rendered `—` where every sibling row draws `▁▁`, because `h2.rst_stream_dropped` was never added to `H2_TRACKED_KEYS` (`bin/src/ctl/top/app.rs`), the list `App::fold_h2_trends` samples. That constant's own doc-comment says it exists so a key cannot silently lose its sparkline. Accepting the frame as rendered would have frozen the gap. ## Changes - `bin/src/ctl/top/app.rs`: track `names::h2::RST_STREAM_DROPPED` beside `WINDOW_UPDATE_DROPPED`. - `snapshot_h2_120x40.snap`: regenerated with `INSTA_UPDATE=always`. The new row now has a `▁▁` trend, and the frame has one fewer blank line below it. No other snapshot was stale. - `.github/workflows/ci.yml`: new `msrv-full` step `cargo test -p sozu --locked ${{ matrix.flags }} --features tui --lib`. No cell enabled `tui`, so `Test sozu` compiled every `top` unit test out. That cell already resolves the tui dependencies for `cargo doc --all-features`, and `--lib` keeps the cost to one extra build of the library test binary (41 s locally with warm deps). The `sozu_top_e2e` step stays with sozu-proxy#1575, and this PR does not touch that hunk. - `CHANGELOG.md`: Fixed entry. ## Red, then green Before (origin/main 57c9269): `cargo test -p sozu --features tui`: `134 passed; 1 failed` (exit 101), and the diff shows `+rst_stream_dropped … —`. With only the `H2_TRACKED_KEYS` line removed, `cargo test -p sozu --features tui --lib snapshot_h2` also fails (`-… ▁▁` / `+… —`, exit 101). After: `cargo test -p sozu --features tui` gives `135 passed; 0 failed` (exit 0). Also exit 0: `cargo build --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd`, `cargo +nightly fmt --all -- --check`, `cargo clippy -p sozu --features tui --all-targets -- -D warnings`, `cargo test -p sozu`, the four `check_doc_citations.py` invocations (the broken fixture exits 1 as expected), and `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked`. Closes sozu-proxy#1576 Signed-off-by: Florentin Dubois <[email protected]>
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.
enqueue_rst_into had no per-insert cap. The only bound was
flush_pending_control_frames' total_rst_streams_queued >=
MAX_PENDING_RST_STREAMS short-circuit, which runs before the drain
loop: it bounds what is written and says nothing about how large the
queue got before anyone looked.
handle_frame runs check_invariants after each dispatch, so the
enqueue_rst calls reached through it are inspected between inserts. It
is also the only production caller of check_invariants, and two insert
paths never reach it. cancel_timed_out_streams is the larger one: it
walks the entire timed-out set and calls enqueue_rst for every entry in
one sweep - an unbounded number of inserts between two checks -
deliberately discarding the flood-violation signal each call returns,
and from Mux::timeout it runs when handle_frame does not run at all.
The DATA-on-closed-stream reset is the other: it sits in
handle_header_state, which readable returns into directly on a branch
that never reaches handle_frame. That second path is separately
rate-limited - record_glitch + check_flood_or_return! cap it at
DEFAULT_MAX_GLITCH_COUNT (100) inside one flood window, and the window
can only half-decay when Mux::ready_inner resamples context.now on a
new outer iteration, which is strictly after an inner iteration that
already ran writable() - so it cannot fill the queue by itself; its
inserts are simply not inspected either.
With max_concurrent_streams raised above 200 (operator-settable up to
MAX_SAFE_CONCURRENT_STREAMS = 10 000) and enough streams idling or
window-stalling into the same sweep, pending_rst_streams.len() passed
the <= MAX_PENDING_RST_STREAMS + 1 bound invariant 3 asserts: a debug
build panicked on the next inbound frame, a release build grew the
queue unbounded. That setting bounds the live set one sweep walks, not
the queue, which holds what every caller queued since the last
successful drain. The reaper is reached from readable(), where a later
handle_frame trips the assertion, and from Mux::timeout, where -
against the fully silent peer that produces a mass reap - handle_frame
never runs at all.
enqueue_rst_into now takes max_pending and returns an EnqueueRstOutcome
(Queued / Deduped / Dropped), mirroring
H2FlowControl::queue_window_update's max_pending-gated
QueueWindowUpdateOutcome::Dropped. At capacity it queues nothing, bumps
no counter, records nothing in rst_sent - the cap is tested before the
dedupe insert, so an id is never marked reset without its frame being
queued - and does not re-arm WRITABLE. enqueue_rst answers with the new
h2.rst_stream_dropped counter and a session-context error! line, the
drop + metric + log shape h2.window_update_dropped already uses for the
sibling control queue.
No RST that would have reached the wire is lost, and the peer is not
left believing a refused stream is live. Invariant 3 keeps
total_rst_streams_queued >= pending_rst_streams.len(), so a full queue
implies total_rst_streams_queued >= MAX_PENDING_RST_STREAMS - the
counter half of the condition flush_pending_control_frames tests before
draining, where it emits GOAWAY(ENHANCE_YOUR_CALM) (RFC 9113 6.8, the
documented answer to RST_STREAM abuse since CVE-2023-44487) and the
connection is torn down instead. The other half is a state gate,
!matches!(self.state, H2State::GoAway | H2State::Error), which the RST
drain beneath it does not share: goaway() enters H2State::GoAway
without clearing pending_rst_streams, so a Mux::timeout reap landing
after the first GOAWAY is dropped with no second escalation while the
drain still serialises what is queued. That window is bounded and
benign - the peer already holds the GOAWAY that made the connection
terminal, and writable()'s GoAway arm force-disconnects on the same
pass. The 200 enqueues that filled the queue each armed WRITABLE, so
the escalation runs on the next writable tick on both reaper call
paths. No new GOAWAY site is added: raising one from enqueue_rst would
re-enter goaway() once per remaining reaped stream, clobbering
zero.storage and inflating h2.goaway.sent.*.
Seen red, with the
pending.len() >= max_pendingguard deleted fromthe top of enqueue_rst_into:
$ cargo test -p sozu-lib --locked mass_reap
---- protocol::mux::h2::tests::
mass_reap_keeps_the_pending_rst_queue_within_its_hard_cap stdout ----
panicked at lib/src/protocol/mux/h2.rs:4650:9:
pending RST queue must stay within its hard cap (escalates at the cap)
test result: FAILED. 0 passed; 1 failed; [exit 101]
That message is check_invariants invariant 3; 4650 is its line in the
mutated tree. The same mutation makes
$ cargo test -p sozu-lib --locked prop_pending_rst_queue_stays_within_its_bound
panicked at quickcheck-1.1.0/src/tester.rs:182:28:
[quickcheck] TEST FAILED. Arguments: ([Reap(118)]) [exit 101]
Moving the guard below rst_sent.insert instead makes
$ cargo test -p sozu-lib --locked
test_enqueue_rst_into_refuses_at_capacity_without_side_effects
panicked at lib/src/protocol/mux/h2.rs:8190:9:
an at-capacity refusal must not record the id as reset [exit 101]
Each test doc-comment now carries the command that reproduces its own
red. Covered by those three plus the four other test_enqueue_rst_into_*
unit tests.
Also relocates the LIFECYCLE.md and doc/testing.md h2.rs line citations
this changeset shifted, mechanically mapped by exact line text against
the branch base and spot-verified; the fc-stall arm site is re-anchored
on its arm_fc_stall call. .github/scripts/check_doc_citations.py --base
origin/main passes.
Closes #1413
Signed-off-by: Florentin Dubois [email protected]