Repository navigation
fix(mux): release the reservation of a dial abandoned after connect - #1717
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 30, 2026 11:32
Selection reserves a connection on the chosen backend before Mux::dial_backend connects, and only a failed connect(2) released it. Three exits past a successful connect dropped the connection and kept the reservation: Connection::new_h2_client returning None, a refused Connection::start_stream, and the register_socket rollback. Each left active_connections one too high for the worker's lifetime, skewing least-loaded, power-of-two and PeakEWMA selection and keeping a removed backend from draining to Closed. Move every step past the connect into Mux::attach_dialed, and have dial_backend push one BackendChange::ConnectionClosed for whichever of its exits returns Err: a single release point a new exit cannot bypass. It records no failure and arms no backoff, since the failure is local. Closes #1713 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/mux-backend-reservation-leak
branch
from
September 30, 2026 12:01
d0bb233 to
8e61f98
Compare
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 #1713
What
Backend selection reserves a connection (
active_connections += 1) beforeMux::dial_backendconnects (#1684/#1709). Before this change, only a failedconnect(2)released that reservation (BackendChange::DialFailed). Three exits after a successful connect dropped the connection and kept the reservation:Connection::new_h2_clientreturnsNonebecause the buffer pool is exhausted;Connection::start_streamrefuses the stream;register_socketrollback.Connectionhas noDrop, so each hit left the backend one connection too high for the rest of the worker's life. That skews least-loaded, power-of-two and PeakEWMA selection, and it keeps a removed backend from ever draining toClosed.Fix
Mux::attach_dialed.Mux::dial_backendpushes oneBackendChange::ConnectionClosedfor whichever exit returnsErr. This single release point also covers any exit added later.ConnectionClosed(dec_connectionsonly), notDialFailed. These failures are local to the proxy, so recording them in the backend'sfailuresand backoff would steer traffic away from a healthy backend.Protocol/security impact: none on the wire. Counters stay correct on local-failure paths (CWE-400 hygiene).
Tests
lib/src/protocol/mux/router.rs: thedial_oneharness is nowdial_with(address, DialFault). It calls the realMux::dial_backendagainst a listening loopback backend with each fault staged:an_h2_client_the_pool_cannot_build_releases_its_reservation: every pool buffer is checked out →MaxBuffers;a_refused_stream_start_releases_its_reservation: the request already holds encoded output (h2: a backend request encoded but not sent is re-linked to a fresh backend with stale HEADERS frames #1632 guard) →MaxSessionsMemory;a_socket_the_poller_refuses_releases_its_reservation: a proxy wrapper whoseregister_socketreturnsEMFILE→MaxSessionsMemory.Each test asserts that the dial failed at its exit and left no router entry. After the ledger drains,
active_connections == 0,failures == 0and the retry policy is stillOKAY. All three were seen red, both on unmodifiedmainand with the release disabled (left: 1, right: 0), and green with the fix.Commands run
cargo +nightly fmt --all --check→ 0cargo +1.93.1 clippy --all-features --all-targets --locked -- -D warnings→ 0RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --locked→ 0cargo test -p sozu-lib -p sozu-command-lib --locked→ 0 (sozu-lib: 1423 passed)RUSTFLAGS='--cfg tokio_unstable' cargo test -p sozu-sim --locked→ 0cargo test -p sozu-e2e --locked -- e2e_session_router_connect_failure_no_leak mux_tests protocol_pair_matrix→ 0 (67 passed)cd fuzz && cargo +nightly fuzz build→ 0check_doc_citations.pywith--self-test,--root .,--root . --base origin/mainand--audit --root .→ 0 for all four. The audit's two advisories are inproxy_protocol/LIFECYCLE.md, which this change does not touch.Docs
lib/src/protocol/mux/LIFECYCLE.md(invariant 14): replaced the "three exits … still do" paragraph and added the new tests to the "Pinned by" list.BackendChange::ConnectionClosed,Mux::dial_backend/Mux::attach_dialedandBackendSelector.CHANGELOG.md: Unreleased / Fixed.