Repository navigation
refactor(mux): make the per-IP limit gate a returned step (#1340, Q6) - #1527
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 25, 2026 11:16
FlorentinDUBOIS
force-pushed
the
refactor/h2-router-cluster-view
branch
from
September 25, 2026 11:30
c1000da to
2e02720
Compare
FlorentinDUBOIS
force-pushed
the
refactor/h2-router-ip-gate-step
branch
from
September 25, 2026 11:32
41157ff to
10d47af
Compare
FlorentinDUBOIS
force-pushed
the
refactor/h2-router-cluster-view
branch
from
September 25, 2026 12:42
2e02720 to
b9f56c1
Compare
FlorentinDUBOIS
force-pushed
the
refactor/h2-router-ip-gate-step
branch
from
September 25, 2026 12:47
10d47af to
f9bc17f
Compare
FlorentinDUBOIS
changed the base branch from
refactor/h2-router-cluster-view
to
main
September 25, 2026 12:47
The last thing `Router::plan_connect` reached `Rc<RefCell<dyn L7Proxy>>` for. It could not follow `clusters()` and `kind()` into the borrowed view, because it is not a read: it calls `SessionManager::cluster_ip_at_limit` AND `SessionManager::track_cluster_ip`, which mutates `connections_per_cluster_ip` — worker-global state keyed on `(cluster, ip)` across every session, read again by `lib/src/tcp.rs`'s own gate for the TCP proxy. So it becomes a step. `Router::plan_connect` answers `ConnectStep::CheckIpLimit(ConnectResume)`, `consult_ip_gate` performs the consult and the track, and `Router::plan_connect_resume` finishes on the verdict. `plan_connect` takes no `L7Proxy` handle at all. Two properties are enforced by types rather than by comment. `ConnectResume` is taken by value, so a parked decision cannot be resumed twice — `H2Shell::settled` taking its parked target, applied here. The resumed call returns `ConnectPlan`, not `ConnectStep`, so a second gate consultation is unrepresentable rather than merely incorrect. Both entries share one `Router::decide_after_gate` body so the gated and ungated paths cannot drift. `Rc<RefCell<dyn L7Proxy>>` production code references in `mux/router.rs` go 4 -> 3, comment lines filtered. That 3 is this stage's floor and not a miss: the remaining three are the import plus `backend_from_request` and `get_backend_for_sticky_session`, which reach `L7Proxy::backends` for selection. Reaching zero means giving selection a borrowed view of backend load state, which is #1340 Question 12's second part — a further stage, not a failure of this one. No behaviour change. `an_admitted_stream_is_counted_before_the_decision_resumes` drives the real three-step sequence for two different frontend tokens from one source IP against a limit of one, and pins that the track lands before the decision resumes. Two tokens rather than two streams on one token, because the gate is deliberately idempotent within a token. Seen red by deleting the `track_cluster_ip` call so the gate returns `Admitted` without counting: the second token is then admitted too. The production diff and the test share no string literal. `cargo test -p sozu-lib` goes 1128 -> 1129. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
refactor/h2-router-ip-gate-step
branch
from
September 25, 2026 13:59
f9bc17f to
04069af
Compare
This was referenced Sep 25, 2026
Closed
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.
Completes the H2 half of Question 6 of #1340. Stacked on #1525; retarget to
mainwhenthat lands.
Why the gate could not be a view
L7Proxy::clustersandL7Proxy::kindbecameRoutingViewin #1525. The per-(cluster, source-IP)limit gate could not follow them, because it is not a read. It consultsSessionManager::cluster_ip_at_limitand callsSessionManager::track_cluster_ip, whichmutates
connections_per_cluster_ip— worker-global state keyed on(cluster, ip)across everysession on the worker, and read again by
lib/src/tcp.rs's own gate for the TCP proxy. Aread-only view cannot carry a mutation, and a trait with a mutating method would be a name that
lies.
So it becomes a step:
Router::plan_connectnow takes noRc<RefCell<dyn L7Proxy>>at all.Two properties the types enforce, rather than comments
ConnectResumeis taken by value. A parked decision cannot be resumed twice. That isH2Shell::settledtaking its parked target, applied to this seam.ConnectPlan, notConnectStep. A second gate consultation isunrepresentable, not merely incorrect.
Both entries — gated and ungated — share one
Router::decide_after_gatebody, so the two pathscannot drift. Drift is the thing a split like this most easily gets wrong.
IpGateVerdict::Admittedcarries no payload, on the same principleH2WritableStateTarget::Flushcarries nobool: it means the embedder has already performedthe track, so there is no binding a later edit could reuse to re-ask a question it has answered.
Counts — and why 3 is the floor, not a miss
Comment lines filtered, production only, in
lib/src/protocol/mux/router.rs:Rc<RefCell<dyn L7Proxy>>production code referencesRemoving the gate leaves
L7Proxyat 3 inrouter.rs— the import plusRouter::backend_from_requestandRouter::get_backend_for_sticky_sessionreachingL7Proxy::backends— and reaching zero requires giving selection a borrowed view of backend loadstate, which is Question 12 part 2, a fourth stage and not a failure of the third.
Across the three PRs of this half:
ProxySession4 → 0 (#1519),L7Proxy5 → 4 (#1525) → 3 (here).The test is red for the resume ordering, not for the gate's verdict
an_admitted_stream_is_counted_before_the_decision_resumesdrives the real production sequence —Router::plan_connect→consult_ip_gate→Router::plan_connect_resume— for two differentfrontend tokens from the same source IP, against a limit of one.
Two tokens rather than two streams on one token, and that is the load-bearing detail: the gate is
deliberately idempotent within a token, because an H2 session multiplexing many streams to one
cluster holds a single slot. A second stream on the same token could never trip the limit and would
prove nothing.
consult_ip_gateis a free function inmod.rsrather than aMuxmethod precisely so the testcan drive it. Testing this ordering through a copy of the logic would prove nothing about the
logic.
Seen red by deleting the
track_cluster_ipcall so the gate returnsAdmittedwithoutcounting:
That is red for the ordering — an admitted stream that resumed uncounted — not for whether the
gate computes the right verdict. The production diff and the test share no string literal.
cargo test -p sozu-libgoes 1128 → 1129 passed.Verification
Feature set
--no-default-features --features crypto-ring,opentelemetry,splice,simd. Every exitcode read directly, never through a pipe.
cargo build --locked <flags>cargo +nightly fmt --all -- --checkcargo clippy --all-targets --locked <flags> -- -D warningscargo test -p sozu-lib --locked <flags>cargo test -p sozu --locked <flags>cargo test -p sozu-e2e --locked <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 warningscheck_doc_citations.py --root .check_doc_citations.py --base c1000daecheck_doc_citations.py --audit --root .RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --lockedcargo bench -p sozu-lib --bench h2_stream_table -- --testCitations remapped by content; the in-place remap was proved equivalent to a base reset (every
guarded doc's citation sequence was byte-identical to base beforehand). All 17 exempt spans (22
endpoints) audited on three keys — byte-identical over the span's entire length rather than
only its endpoints, the base→head line map from each source file's own content diff, and the
enclosing
fnmatched by name with an enclosing-type fallback. All 17 hold.One citation was converted to a symbol rather than renumbered:
Mux::timeout_inner'smod.rs:2776. It is correct at head, but the number is one this changeset reused for differentcode, so the drift rule compares it against what the base put there — the class
#1447 named. The prose already names the symbol, so the line added nothing.
e2e was run in a quiet window, with 1-minute loadavg and
pgrep sozu_e2e | wc -lrecorded beforeand after.
No
sozu-simscenario, workload weight or assertion is touched; this PR modifies no file undersim/.