Repository navigation
Description
Summary
Since #1684 / #1709, backend selection in the HTTP mux reserves a connection on the chosen backend (BackendMap::reserve_backend / reserve_sticky_backend -> Backend::reserve_connection, active_connections += 1) before Mux::dial_backend connects. Only a failed connect(2) releases it (BackendChange::DialFailed). Three later exits of Mux::dial_backend, all past a successful connect(2), drop the new connection without releasing the reservation, so the backend's active_connections stays one too high forever.
Verified on origin/main at a810211:
- selection reserves:
lib/src/backends.rs:845-859(reserve_backend),lib/src/backends.rs:866-891(reserve_sticky_backend), called fromRegistrySelector::selectinlib/src/protocol/mux/mod.rs:3905-3914; - the only release on the dial path is the
connect(2)error arm:lib/src/protocol/mux/mod.rs:2390-2411(BackendChange::DialFailed); - (a)
Connection::new_h2_clientreturnsNone(buffer pool exhausted):lib/src/protocol/mux/mod.rs:2438-2455, returnsErr(MaxBuffers)with no delta; - (b)
Connection::start_streamrefuses (for a fresh H2 client, the h2: a backend request encoded but not sent is re-linked to a fresh backend with stale HEADERS frames #1632 guard on a non-emptyfront.out, or the peer'smax_concurrent_streams):lib/src/protocol/mux/mod.rs:2470-2478, returnsErr(MaxSessionsMemory)with no delta; - (c)
register_socketfails (EMFILE/ENFILE-class pressure):lib/src/protocol/mux/mod.rs:2503-2546, rolls back the gauges,active_requestsand the slab session, but notactive_connections.
Connection has no Drop impl, so dropping it runs no bookkeeping. lib/src/protocol/mux/LIFECYCLE.md:1981-1987 already records the three exits as leaking ("They leaked the count Backend::try_connect took before #1684 in exactly the same way, and still do.").
Impact
Each hit permanently inflates Backend::active_connections by one:
- least-loaded (
LoadMetric::Connections), power-of-two and PeakEWMA selection steer traffic away from the backend as if it held phantom connections; - a
Closingbackend never drains to zero, so it never reachesClosed; - the leak is triggered by local resource pressure (buffer pool, fd exhaustion), exactly when balancing matters most, and accumulates for the worker's lifetime.
Expected
Every exit of Mux::dial_backend after a successful connect(2) releases the reservation with a plain dec_connections (BackendChange::ConnectionClosed), without recording a backend failure: the backend did not fail, the proxy did.
Repro
Unit tests driving Mux::dial_backend (the dial_one harness in lib/src/protocol/mux/router.rs) for each exit, asserting active_connections == 0 after the ledger drain; they fail on origin/main with active_connections == 1.
Activity
fix(mux): release the reservation of a dial abandoned after connect
fix(mux): release the reservation of a dial abandoned after connect (s…