Repository navigation
fix(mux-h2): ignore frames on refused streams like on reset streams - #1817
Merged
Merged
Conversation
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]>
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.
Fixes #1815
What
A stream Sōzu refuses with
RST_STREAM(REFUSED_STREAM)is never registered, andConnectionH2::enqueue_rstonly 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: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 withPROTOCOL_ERRORinstead ofNO_ERROR;RST_STREAM(STREAM_CLOSED).RFC 9113 §5.1 says those frames are ignored. The §5.1.1
PROTOCOL_ERRORreasoning only holds for ids the client skipped.Design
H2StreamTable::remember_refusedpushes a refused id onto therecently_resetring. The push/evict block ofH2StreamTable::removemoves 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;enqueue_rstitself to skip SETTINGS back-pressure.HEADERS and DATA on a refused id now take the existing
was_reset_locallybranch ofhandle_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:
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_errorstays green).flood_refused_streams/flood_refusal_ignoreddetection works as before.rst_sent.Trade-offs
GOAWAY(PROTOCOL_ERROR).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: oneRST_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 isPROTOCOL_ERROR. Green:NO_ERROR.refused_streams_share_the_recently_reset_bound(h2_stream_table.rs): bound, eviction, allowances dropped, dedupe.Mutation checks:
remember_refusedcall fails the first two tests;refuse_stream_and_discardfails the drain test.Every existing #1784 / #1798 test stays green and unmodified.
Validation
cargo +nightly fmt --check: okcargo +1.93.1 clippy --all-features --all-targets --locked -- -D warnings: okRUSTDOCFLAGS="-D warnings" cargo +1.93.1 doc --no-deps --locked -p sozu-lib: okcargo +1.93.1 test -p sozu-lib --lib --all-features --locked: 1592 passedcargo test -p sozu-e2e --locked --features opentelemetry,splice,simd -- --test-threads=4 h2_security flood rapid_reset goaway: 128 passed, 1 failed. The failure wastest_h2_rapid_reset_triggers_goaway(no GOAWAY read within the window) at a host load average of about 80. It also fails onorigin/mainunder 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.check_doc_citations.py --self-testand--root . --base origin/main: ok (renumbered theh2.rsline citations indoc/h2_mux_internals.mdthat moved)Docs:
doc/configure.md,doc/h2_mux_internals.md,lib/src/protocol/mux/LIFECYCLE.md, andCHANGELOG.md. The #1798 entry now points to this fix, and there is a new Fixed entry.