Repository navigation
docs(mux-h2): say that the advertised connection-level receive window is not enforced - #1510
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 24, 2026 18:18
… is not enforced Sōzu advertises a connection-level receive window and then checks nothing against it. A peer's allowance is RFC 9113 §6.9.2's fixed 65535 octets plus every stream-0 WINDOW_UPDATE we send — the one-shot enlargement to H2ConnectionConfig::initial_connection_window and the periodic grants back — while H2FlowControl::window is the SEND window, peer-granted credit for our own writes, and H2FlowControl::account_received_bytes is a counter whose only job is deciding when to hand credit back. No state is decremented by an inbound DATA frame, so none can go negative, and the only H2Error::FlowControlError the connection emits at all comes from ConnectionH2::handle_window_update_frame on a SEND-window overflow past 2^31-1. Measured in #1488: 106496 octets of DATA accepted against an advertised 98303, with no GOAWAY and no FLOW_CONTROL_ERROR. #1488 offered two defensible resolutions — enforce the advertised window, or document that the buffer pool is the real boundary and say what the advertised value means — and the decision was the second. This is that, and only that: no enforcement, no credit bookkeeping, no observable behaviour change. The two Rust edits are a //! block and one /// line. What the configured number governs here is the size of the one-shot WINDOW_UPDATE(0, …) enlargement and the grant-back cadence (ConnectionH2::handle_data_frame passes initial_connection_window / 2 as its threshold). What bounds memory — the thing flow control exists to protect — is the buffer pool, reached through the BufferSource contract, whose refusal degrades one stream with RST_STREAM(REFUSED_STREAM) and never the connection; buffer_source.rs's module doc is that contract and is pointed at rather than restated. The consequence is stated rather than softened: a peer that trusts the advertisement has no way to discover the real limit, and RFC 9113 §6.9.1 makes enforcement a MUST, so a conformance suite will flag this. h2_flow_control.rs's module doc holds the canonical statement. H2ConnectionConfig::initial_connection_window's doc comment carries the qualifier and points there, kept to a single line on purpose: h2.rs is cited by line roughly a hundred times across the guarded prose, and an inserted line converted 53 live citations into re-anchors on the first attempt — #1509 exists precisely because a re-anchor preserves the pointer and not the claim. doc/h2_mux_internals.md repeats the statement beside the H2ConnectionConfig table, and its file-role row no longer calls H2FlowControl a "send/receive window". LIFECYCLE.md §1.3 called it a "send/recv window", which is the false claim in miniature, and now names the receive side as the byte accounting it is. doc/configure.md qualifies both rows that called h2_initial_connection_window a "receive window" with no qualifier — the operator raising it to bound memory is exactly who that misleads. doc/testing.md records why the H2 simulator (#1359 C4) carries no connection-level flow-control property: the one asserting the connection window is never overcommitted is false against today's code, so it was rewritten into per-stream credit attribution rather than loosened until it passed, because an assertion weak enough to go green would certify the gap. Its absence is deliberate and it goes back in, in its original form, once enforcement lands. Verified: cargo +nightly fmt --all -- --check -> 0; cargo build --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd -> 0; cargo clippy --all-targets (same flags) -- -D warnings -> 0; cargo test -p sozu-lib -> 0 (1114 passed); -p sozu -> 0 (113 passed); -p sozu-e2e --skip tests::fuzz_tests:: -> 0 (447 passed); RUSTFLAGS="--cfg tokio_unstable" cargo test/clippy -p sozu-sim -> 0; check_doc_citations.py --root . -> 0, --base bdda063 -> 0 (306 compared, 0 drifted, 0 re-anchored exempt), --audit -> 7 findings, the same 7 the base revision reports; RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features -> 0; cargo bench -p sozu-lib --bench h2_stream_table -- --test -> 0. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
docs/h2-connection-window-advertisement
branch
from
September 24, 2026 18:21
1c986d8 to
f9e599f
Compare
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 24, 2026
…es at their flush points `ConnectionH2::finalize_write` and `ConnectionH2::flush_pending_control_frames` were the last two core functions that read `ConnectionH2::tls_wants_write`, acted on the answer, and read it again. Both now answer a step and let the shell that owns the socket perform it, on the `poll_read_target` / `handle_read` protocol this module already uses for the read half. Issue #1339, Q10. `finalize_write` gains a leading `tls_wants_write: bool` and returns `H2FinalizeTarget`: `Done(MuxResult)` for the RFC 9113 6.8 graceful GOAWAY and the four readiness answers of LIFECYCLE 9 invariant 16, `Flush` / `SkipFlush` for the two that need the TLS step. `write_streams` -- already the only site that touches the socket on the stream-write path -- reads the query, performs `flush_tls_records` for `Flush` and not for `SkipFlush`, reads it again, and hands that second answer to the new `finalize_write_after_flush`. The two stay two variants rather than one boolean because `h2_close::finalize_action` already distinguishes them, and the post-flush read stays a second call rather than a reused binding because it asks a different question: not "does rustls hold records" but "did the step between them land" -- `socket_write(&[])`'s `(size, status)` is discarded, so nothing else on this path can tell. `flush_pending_control_frames` answers `H2ControlFlushTarget` instead of `Option<MuxResult>`. `Proceed` is the former `None`, `Done(MuxResult)` the former `Some`, and `Stalled` is new: the zero-buffer resume, the WINDOW_UPDATE drain and the RST_STREAM drain used to read `tls_wants_write` and call `ensure_tls_flushed` themselves, and now return `Stalled` for `writable` to do it once for all three. That query could not become an input -- it has to be read after the `flush_zero_to_socket` whose stall produced it, because that write is what changes the answer. `ensure_tls_flushed`'s production call sites fall from eight to six. `flush_zero_to_socket` stays inside the function: it is a byte mover on the control-frame path, not a TLS seam. Behaviour-preserving. `cargo test -p sozu-lib` reads `1115 passed; 0 failed` at 84d979f and `1115 passed; 0 failed` here; nothing on the wire, in a route, a metric, a configuration key or a CLI flag moves. One ordering detail is real and unobservable rather than absent: `write_streams` reads `tls_wants_write` before `finalize_write` runs the graceful-GOAWAY check that used to precede the query, so on that path the query now happens and its value is discarded. `SocketHandler::socket_wants_write` is free of side effects and no fixture counts it -- `BackpressuredTlsSocket` models the record state rather than scripting an answer sequence, and counts flushes only. The count of `self.socket` reaches above `mod tests` is unchanged at eleven, which is the honest measure of this step: neither function ever held one, both reached the socket only through the three named seams of #1499. Six `TO SEE THIS RED` recipes repaired, each applied as written and the failure recorded. Four named `self.socket.socket_wants_write()` at sites #1499 and touched anything: the WINDOW_UPDATE-drain and RST_STREAM-drain stages, and the `error_close_action` and `goaway_close_action` call sites in `writable`. A fifth named `self.socket.socket_write(&[])` in the GoAway arm's `CloseAction::Flush` body, which is `self.flush_tls_records()`. The sixth, on `a_finalized_write_pass_flushes_once_and_re_arms_while_records_survive`, this changeset itself made wrong. Measured: the two drain recipes and both halves of the finalize recipe give `1114 passed; 1 failed` naming only their own test, `error_close_action(false)` gives `1114 passed; 1 failed` (the stale text said `1097`), and the `goaway_close_action` post-flush constant and the deferred-GOAWAY-flush recipe each give `1113 passed; 2 failed` (the stale text said `1096`), the second failure being `a_flush_that_does_not_drain_keeps_the_connection_open`. The three `log_context!` recipes that name `self.socket` deliberately were read and left alone: they ask a reader to put back a removed form, and the form they replace is still there. Docs move in the same changeset: `doc/h2_mux_internals.md`'s `ensure_tls_flushed`, `flush_pending_control_frames()`, `write_streams()` and `finalize_write()` sections, `h2_close.rs`'s module header, and LIFECYCLE.md's fourth-site paragraph. LIFECYCLE.md's `h2.rs:3336` pin drops to a bare `h2.rs` because the sentence holding it already names `finalize_write` -- #1509's form, and no line pin is reintroduced. The 35 remaining `h2.rs` line citations across LIFECYCLE.md, `doc/h2_mux_internals.md` and `doc/testing.md` are renumbered, and each one was checked twice: it lands on the byte-identical line text, and inside the identically-named enclosing item, that it named at 84d979f. That second key is what covers the generic anchors in the set -- `Position::Server => {`, `match error {`, and a `// RFC 9113 6.5` comment that exists in two different functions -- which text identity alone would pass. The drift gate exempts a re-anchored span from comparison, so it cannot tell a correct move from a wrong one; this audit is what does. The numbering was derived against 68523cc and holds unchanged at 84d979f: #1510 replaced exactly one `h2.rs` line and added none, so `git diff --numstat` over that range reads `1 1`, and the line it replaced (`H2ConnectionConfig::h2_initial_connection_window`'s doc comment) is named by no citation in the tree. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Sep 24, 2026
…es at their flush points (#1512) `ConnectionH2::finalize_write` and `ConnectionH2::flush_pending_control_frames` were the last two core functions that read `ConnectionH2::tls_wants_write`, acted on the answer, and read it again. Both now answer a step and let the shell that owns the socket perform it, on the `poll_read_target` / `handle_read` protocol this module already uses for the read half. Issue #1339, Q10. `finalize_write` gains a leading `tls_wants_write: bool` and returns `H2FinalizeTarget`: `Done(MuxResult)` for the RFC 9113 6.8 graceful GOAWAY and the four readiness answers of LIFECYCLE 9 invariant 16, `Flush` / `SkipFlush` for the two that need the TLS step. `write_streams` -- already the only site that touches the socket on the stream-write path -- reads the query, performs `flush_tls_records` for `Flush` and not for `SkipFlush`, reads it again, and hands that second answer to the new `finalize_write_after_flush`. The two stay two variants rather than one boolean because `h2_close::finalize_action` already distinguishes them, and the post-flush read stays a second call rather than a reused binding because it asks a different question: not "does rustls hold records" but "did the step between them land" -- `socket_write(&[])`'s `(size, status)` is discarded, so nothing else on this path can tell. `flush_pending_control_frames` answers `H2ControlFlushTarget` instead of `Option<MuxResult>`. `Proceed` is the former `None`, `Done(MuxResult)` the former `Some`, and `Stalled` is new: the zero-buffer resume, the WINDOW_UPDATE drain and the RST_STREAM drain used to read `tls_wants_write` and call `ensure_tls_flushed` themselves, and now return `Stalled` for `writable` to do it once for all three. That query could not become an input -- it has to be read after the `flush_zero_to_socket` whose stall produced it, because that write is what changes the answer. `ensure_tls_flushed`'s production call sites fall from eight to six. `flush_zero_to_socket` stays inside the function: it is a byte mover on the control-frame path, not a TLS seam. Behaviour-preserving. `cargo test -p sozu-lib` reads `1115 passed; 0 failed` at 84d979f and `1115 passed; 0 failed` here; nothing on the wire, in a route, a metric, a configuration key or a CLI flag moves. One ordering detail is real and unobservable rather than absent: `write_streams` reads `tls_wants_write` before `finalize_write` runs the graceful-GOAWAY check that used to precede the query, so on that path the query now happens and its value is discarded. `SocketHandler::socket_wants_write` is free of side effects and no fixture counts it -- `BackpressuredTlsSocket` models the record state rather than scripting an answer sequence, and counts flushes only. The count of `self.socket` reaches above `mod tests` is unchanged at eleven, which is the honest measure of this step: neither function ever held one, both reached the socket only through the three named seams of #1499. Six `TO SEE THIS RED` recipes repaired, each applied as written and the failure recorded. Four named `self.socket.socket_wants_write()` at sites #1499 and touched anything: the WINDOW_UPDATE-drain and RST_STREAM-drain stages, and the `error_close_action` and `goaway_close_action` call sites in `writable`. A fifth named `self.socket.socket_write(&[])` in the GoAway arm's `CloseAction::Flush` body, which is `self.flush_tls_records()`. The sixth, on `a_finalized_write_pass_flushes_once_and_re_arms_while_records_survive`, this changeset itself made wrong. Measured: the two drain recipes and both halves of the finalize recipe give `1114 passed; 1 failed` naming only their own test, `error_close_action(false)` gives `1114 passed; 1 failed` (the stale text said `1097`), and the `goaway_close_action` post-flush constant and the deferred-GOAWAY-flush recipe each give `1113 passed; 2 failed` (the stale text said `1096`), the second failure being `a_flush_that_does_not_drain_keeps_the_connection_open`. The three `log_context!` recipes that name `self.socket` deliberately were read and left alone: they ask a reader to put back a removed form, and the form they replace is still there. Docs move in the same changeset: `doc/h2_mux_internals.md`'s `ensure_tls_flushed`, `flush_pending_control_frames()`, `write_streams()` and `finalize_write()` sections, `h2_close.rs`'s module header, and LIFECYCLE.md's fourth-site paragraph. LIFECYCLE.md's `h2.rs:3336` pin drops to a bare `h2.rs` because the sentence holding it already names `finalize_write` -- #1509's form, and no line pin is reintroduced. The 35 remaining `h2.rs` line citations across LIFECYCLE.md, `doc/h2_mux_internals.md` and `doc/testing.md` are renumbered, and each one was checked twice: it lands on the byte-identical line text, and inside the identically-named enclosing item, that it named at 84d979f. That second key is what covers the generic anchors in the set -- `Position::Server => {`, `match error {`, and a `// RFC 9113 6.5` comment that exists in two different functions -- which text identity alone would pass. The drift gate exempts a re-anchored span from comparison, so it cannot tell a correct move from a wrong one; this audit is what does. The numbering was derived against 68523cc and holds unchanged at 84d979f: #1510 replaced exactly one `h2.rs` line and added none, so `git diff --numstat` over that range reads `1 1`, and the line it replaced (`H2ConnectionConfig::h2_initial_connection_window`'s doc comment) is named by no citation in the tree. Signed-off-by: Florentin Dubois <[email protected]>
This was referenced Sep 24, 2026
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.
Closes #1488 by taking its second resolution.
What #1488 reports
Sōzu advertises a connection-level receive window and then checks nothing against
it. A peer's allowance is RFC 9113 §6.9.2's fixed 65535 octets plus every stream-0
WINDOW_UPDATEwe send — the one-shot enlargement toH2ConnectionConfig::initial_connection_window, then the periodic grants back.H2FlowControl::windowis the send window, peer-granted credit for our ownwrites;
H2FlowControl::account_received_bytesis a counter whose only job isdeciding when to hand credit back. No state is decremented by an inbound DATA
frame, so none can go negative, and the only
H2Error::FlowControlErrortheconnection emits at all comes from
ConnectionH2::handle_window_update_frameon aSEND-window overflow past 2^31-1.
Measured in #1488: 106496 octets of DATA accepted against an advertised 98303
(the 65535 default plus one 32768 grant), with no GOAWAY and no
FLOW_CONTROL_ERROR. Those are the issue's own figures, quoted rather thanre-measured.
Why enforcement is not implemented here
#1488 is explicit that it is a design call rather than a bug report, and offers two
defensible resolutions: enforce the advertised window and emit
FLOW_CONTROL_ERROR, or document that the buffer pool is the real boundary and saywhat the advertised value means. The decision was the second, and this changeset
is that and only that. No enforcement, no credit bookkeeping, no observable
behaviour change, no new metric, no configuration default moved. The only two Rust
edits are a
//!block and one///line.The pool is a defensible boundary — it bounds memory, which is the thing flow
control exists to protect, and does so without per-connection credit bookkeeping.
What is not defensible is advertising a number nothing enforces, so the gap is
stated rather than softened: a peer that trusts the advertisement has no way to
discover the real limit, RFC 9113 §6.9.1 makes enforcement a MUST, and a
conformance suite will flag this as a §6.9.1 violation. Closing it means tracking
outstanding inbound credit and emitting
FLOW_CONTROL_ERROR, which changesobservable behaviour and belongs to its own changeset.
What is documented, and where
lib/src/protocol/mux/h2_flow_control.rs//!section beside the ones the module already carries: what the advertised value governs (the one-shot enlargement's size, and the grant-back cadence —ConnectionH2::handle_data_framepassesinitial_connection_window / 2as its threshold), what it is not, what the real boundary is, and the consequence.lib/src/protocol/mux/h2.rsH2ConnectionConfig::initial_connection_window's own doc comment carries the qualifier and points there.doc/h2_mux_internals.mdH2ConnectionConfigtable that names the knob; the file-role row no longer callsH2FlowControla "send/receive window".lib/src/protocol/mux/LIFECYCLE.mddoc/configure.mdh2_initial_connection_windowa "receive window" with no qualifier. The operator raising it to bound memory is exactly who that misleads.doc/testing.mdThe buffer-pool half points at
buffer_source.rs's module doc rather thanrestating it: that contract landed in #1496 and already says the governing rule —
a refusal degrades one stream with
RST_STREAM(REFUSED_STREAM)and never theconnection.
The test-coverage consequence
doc/testing.mdnow records that the property asserting the connection window isnever overcommitted is false against today's code, so it was rewritten into
per-stream credit attribution
(
h2_inbound_credit_is_attributed_to_the_stream_that_spent_it) rather thanloosened until it passed — an assertion weak enough to go green would certify the
gap as intended behaviour. Its absence is deliberate, and it goes back in, in its
original form, once enforcement lands. That is recorded where someone deciding
whether to add such a property will actually look.
A note on the
h2.rsdoc commentIt is one line on purpose.
h2.rsis cited by line roughly a hundred times acrossthe guarded prose, and the first attempt — a six-line
///block — converted 53live citations into re-anchors and turned
check_doc_citations.pyred. #1509exists precisely because a re-anchor preserves the pointer and not the claim, so
the qualifier was compressed to a single replaced line instead. The
changeset adds zero re-anchored spans.
Verification
Every command's exit code read directly, never through a pipe.
cargo +nightly fmt --all -- --checkcargo build --locked --no-default-features --features crypto-ring,opentelemetry,splice,simdcargo clippy --all-targets --locked(same flags)-- -D warningscargo test -p sozu-lib --locked(same flags)cargo test -p sozu --locked(same flags)cargo test -p sozu-e2e --locked(same flags)-- --skip tests::fuzz_tests::RUSTFLAGS="--cfg tokio_unstable" cargo test -p sozu-sim --lockedRUSTFLAGS="--cfg tokio_unstable" cargo clippy -p sozu-sim --all-targets --locked -- -D warningspython3 .github/scripts/check_doc_citations.py --root .python3 .github/scripts/check_doc_citations.py --base bdda063ec3c985909a4616ae7ec110224108f067python3 .github/scripts/check_doc_citations.py --audit --root .RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --lockedcargo bench -p sozu-lib --bench h2_stream_table -- --testThe
sozu-e2erun took a quiet window:pgrep sozu_e2e | wc -lread 0 and theone-minute load average was 3.40 before it started.