Skip to content

mux: three Mux::dial_backend exits after connect leak the backend connection reservation #1713

Closed

Description

@FlorentinDUBOIS

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 from RegistrySelector::select in lib/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_client returns None (buffer pool exhausted): lib/src/protocol/mux/mod.rs:2438-2455, returns Err(MaxBuffers) with no delta;
  • (b) Connection::start_stream refuses (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-empty front.out, or the peer's max_concurrent_streams): lib/src/protocol/mux/mod.rs:2470-2478, returns Err(MaxSessionsMemory) with no delta;
  • (c) register_socket fails (EMFILE/ENFILE-class pressure): lib/src/protocol/mux/mod.rs:2503-2546, rolls back the gauges, active_requests and the slab session, but not active_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 Closing backend never drains to zero, so it never reaches Closed;
  • 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.

Follow-up noted on #1709 and #1710.

Activity

  1. added a commit that references this issue on Sep 30, 2026
    8e61f98
  2. added a commit that references this issue on Oct 2, 2026
    ac2789f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions