Skip to content

fix(mux-h2): ignore frames on refused streams like on reset streams - #1817

Merged
FlorentinDUBOIS merged 3 commits into
mainfrom
fix/h2-refused-streams-ignore-frames
Oct 3, 2026
Merged

FlorentinDUBOIS merged 3 commits into
mainfrom
fix/h2-refused-streams-ignore-frames

Conversation

@FlorentinDUBOIS

@FlorentinDUBOIS FlorentinDUBOIS commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1815

What

A stream Sōzu refuses with RST_STREAM(REFUSED_STREAM) is never registered, and ConnectionH2::enqueue_rst only records registered streams, so the bounded recently-reset set (#1784) did not know it. #1798 documented the result as an accepted limitation. Frames the client sent on the stream before it read the refusal were not ignored:

  • request trailers ended the connection with RST_STREAM(REFUSED_STREAM), RST_STREAM(STREAM_CLOSED), GOAWAY(PROTOCOL_ERROR) (GOAWAY(STREAM_CLOSED) once a later stream was accepted), and every stream in flight went with it. A graceful drain could end with PROTOCOL_ERROR instead of NO_ERROR;
  • each DATA frame cost one glitch and one RST_STREAM(STREAM_CLOSED).

RFC 9113 §5.1 says those frames are ignored. The §5.1.1 PROTOCOL_ERROR reasoning only holds for ids the client skipped.

Design

H2StreamTable::remember_refused pushes a refused id onto the recently_reset ring. The push/evict block of H2StreamTable::remove moves into a shared private helper, so refused ids get the same bound (256), the same eviction, and their allowances are dropped along with them. It is called at every refusal:

  • ConnectionH2::refuse_stream_and_discard: draining, SETTINGS_MAX_CONCURRENT_STREAMS, buffer-pool exhaustion, and the oversized CONTINUATION block. That last one removes its stream before refusing it, so without this it would be the only refusal still unremembered;
  • the soft flood refusal branch, which calls enqueue_rst itself to skip SETTINGS back-pressure.

HEADERS and DATA on a refused id now take the existing was_reset_locally branch of handle_header_state. HEADERS blocks are decoded so HPACK stays in sync. DATA is credited to the connection window (skip_orphaned_data_payload). The existing allowances apply: two header blocks, and DATA within the stream's initial window. Past them, each frame counts one glitch, and an empty DATA frame without END_STREAM still counts toward the empty-DATA limit.

Unchanged:

  • HEADERS on a skipped id still gets GOAWAY(PROTOCOL_ERROR). The ring lookup comes before that branch, and a skipped id is never in the ring (headers_below_a_refused_stream_id_is_a_protocol_error stays green).
  • RST_STREAM never enters the reset branch, so flood_refused_streams / flood_refusal_ignored detection works as before.
  • No id is added to rst_sent.

Trade-offs

  • Refused ids share the 256-entry ring with reset streams. A burst of refusals can evict a reset stream's memory earlier. Its late frames then fall back to the closed-stream rules, which is what already happens past 256 resets.
  • A refused id evicted from the ring gets the old behaviour back: trailers on it cost GOAWAY(PROTOCOL_ERROR).
  • Each refused stream gets the reset-stream allowance before frames count as glitches. Allowances are held for at most RESET_ALLOWANCES_CAPACITY (512) streams, and every refusal still costs its own glitch once SETTINGS are acknowledged. So a client opening refused streams to spend their allowances runs into the glitch budget first.

Tests

The red runs used the new tests on origin/main (6c3b8e89) production code:

  • trailers_on_a_refused_stream_are_ignored: red, got [RST(5, REFUSED_STREAM), RST(5, STREAM_CLOSED), GOAWAY(PROTOCOL_ERROR)]. Green: one RST on stream 5, no GOAWAY, streams 1 and 3 survive, a later PING is answered, only the refusal costs a glitch, and an entry indexed by the ignored trailer block resolves in the connection's HPACK decoder.
  • data_on_a_refused_stream_is_ignored_and_credited: 65535 bytes in 3×16384 + 16383. Red: one RST_STREAM(STREAM_CLOSED) per DATA frame. Green: no RST past the refusal, no glitch past the refusal, and stream-0 WINDOW_UPDATE credit exactly equal to the 65535 bytes ignored (a double credit fails).
  • a_drain_with_a_refused_upload_carrying_trailers_ends_with_no_error: red, the first GOAWAY is PROTOCOL_ERROR. Green: NO_ERROR.
  • refused_streams_share_the_recently_reset_bound (h2_stream_table.rs): bound, eviction, allowances dropped, dedupe.

Mutation checks:

  • dropping the soft-refusal remember_refused call fails the first two tests;
  • dropping the call in refuse_stream_and_discard fails the drain test.

Every existing #1784 / #1798 test stays green and unmodified.

Validation

  • cargo +nightly fmt --check: ok
  • cargo +1.93.1 clippy --all-features --all-targets --locked -- -D warnings: ok
  • RUSTDOCFLAGS="-D warnings" cargo +1.93.1 doc --no-deps --locked -p sozu-lib: ok
  • cargo +1.93.1 test -p sozu-lib --lib --all-features --locked: 1592 passed
  • cargo test -p sozu-e2e --locked --features opentelemetry,splice,simd -- --test-threads=4 h2_security flood rapid_reset goaway: 128 passed, 1 failed. The failure was test_h2_rapid_reset_triggers_goaway (no GOAWAY read within the window) at a host load average of about 80. It also fails on origin/main under the same load (1 run out of 3), and it passed 3 runs out of 3 on this branch at load ~50. It is load-sensitive and not affected by this change, since RST_STREAM frames do not take the changed path.
  • Full e2e suite: not run, the host was too loaded.
  • check_doc_citations.py --self-test and --root . --base origin/main: ok (renumbered the h2.rs line citations in doc/h2_mux_internals.md that moved)

Docs: doc/configure.md, doc/h2_mux_internals.md, lib/src/protocol/mux/LIFECYCLE.md, and CHANGELOG.md. The #1798 entry now points to this fix, and there is a new Fixed entry.

A stream refused with RST_STREAM(REFUSED_STREAM) - soft flood refusal,
SETTINGS_MAX_CONCURRENT_STREAMS, graceful drain, buffer-pool exhaustion,
oversized CONTINUATION block - is never registered, so the bounded
recently-reset set did not know it. Request trailers the client sent
before reading the refusal ended the connection with
GOAWAY(PROTOCOL_ERROR), a drain could end with PROTOCOL_ERROR instead of
NO_ERROR, and each DATA frame cost a glitch and a RST_STREAM(STREAM_CLOSED).

Every refusal now records the id in that set through
H2StreamTable::remember_refused, sharing its bound, eviction and
per-stream allowances, so those frames are ignored as RFC 9113 section 5.1
requires and DATA is still credited to the connection window. HEADERS on
an id the client skipped keeps its PROTOCOL_ERROR, and a client reset of a
refused stream still ends the soft refusal.

Fixes #1815

Signed-off-by: Florentin Dubois <[email protected]>
…ream tests

Buffer-pool refusals count no glitch, and no refusal counts one before
the client acknowledges Sōzu's SETTINGS (bounded by the 5 s
SETTINGS_ACK_TIMEOUT); the oversized CONTINUATION refusal counts as a
provoked reset and records its id on backend connections too. Say so in
CHANGELOG.md, doc/configure.md and doc/h2_mux_internals.md instead of
claiming every refusal costs a glitch on a frontend connection.

The refused-DATA test now asserts the exact connection-window credit, so
a double credit fails, and the refused-trailers test indexes an entry in
the ignored block and resolves it, proving the HPACK decoder stays in step.

Refs #1815

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit bd19a78 into main Oct 3, 2026
23 checks passed
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.

mux-h2: frames on refused streams are not ignored like frames on reset streams

1 participant