Repository navigation
fix(mux): never reuse a pooled connection to a removed backend - #1743
Merged
Merged
Conversation
FlorentinDUBOIS
force-pushed
the
fix/mux-backend-reuse-after-cluster-removal
branch
from
October 1, 2026 11:48
1de3764 to
e20f543
Compare
This was referenced Oct 1, 2026
The pool-reuse scan of Router::decide_after_gate matched an H1 keep-alive or H2 backend connection by cluster id alone. A cluster id outlives RemoveCluster followed by AddCluster of the same id, and a cluster outlives RemoveBackend, so a session could send a new request to a backend the configuration no longer held. BackendList::remove_backend and BackendMap::remove_cluster now mark every backend they drop Closing. The mux reads that status through BackendRegistry::is_retired and RoutingView::with_backend_retired, and the scan skips such a connection: it drains what it carries and takes no new stream. A backend added again is a new Rc in a new slot, so the next request dials it. Fixes #1735 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/mux-backend-reuse-after-cluster-removal
branch
from
October 1, 2026 15:33
e20f543 to
c7eb12e
Compare
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 1, 2026
…dle (#1765) Fixes #1760 ## What changes - **Close idle retired connections.** Since #1743 a pooled backend connection whose backend left the configuration is not reused, but it stayed open until the frontend session ended, so the removed backend never went from `Closing` to `Closed`. `Mux::ready_inner` now drops such a connection once it carries no stream (H1 keep-alive, or H2 with an empty stream table) through `Connection::force_disconnect`; the dead-backend sweep closes it and releases its connection on the backend. A connection already idle at removal time is closed on its session's next event. `RemovedBackendHasNoConnections` is unchanged: it fires when the last `Rc` of the backend drops, which the session's `BackendRegistry` holds until the session closes. - **Reload side effect, documented.** A reload changing a backend's weight, `sticky_id` or `backup` is applied as `RemoveBackend` then `AddBackend` (`ConfigState::diff`), so live sessions now drop their pooled connection to that backend and dial it again. CHANGELOG and `lib/src/protocol/mux/LIFECYCLE.md`. ## Tests - e2e `test_removed_backend_is_neither_reused_nor_kept`: `RemoveBackend` within a surviving cluster; the next request reaches the remaining backend and the removed backend's connection is closed. Fails on #1743's head (connection still open), passes here. - `a_retired_backend_connection_is_never_reused`: the reuse skip of #1743 for H2 Connected, H2 Connecting and H1 KeepAlive, with a live-backend premise per arm. - `idle_pooled_backend_names_only_streamless_pooled_connections`. ## Validation - `cargo +nightly fmt --all --check` - `cargo +1.93.1 clippy --all-features --all-targets --locked -- -D warnings` - `RUSTDOCFLAGS="-D warnings" cargo doc --all-features --no-deps` - `cargo test -p sozu-lib --all-features` - `cargo test -p sozu-e2e --locked --features opentelemetry,splice,simd -- remove_cluster_tests mux_tests keep_alive` - `cargo +nightly fuzz build` - `check_doc_citations.py` in its four modes Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 3, 2026
…1809) Audit of the docs, `bin/config.toml` and `os-build/config.toml` against everything merged on `main` from 2026-10-01 to 2026-10-03 (43 commits, #1724 through #1808). Most of the new keys were already documented by their own PRs (`max_connection_attempts`, `h2_stream_refusal_percent`, health check `mode`/`accepted_statuses`, the raised flood defaults, the 16 MiB connection window). This PR fixes what was still stale. | Area | Where | Was | Now | |---|---|---|---| | #1806 | `bin/config.toml`, `os-build/config.toml` answer comments | 503 only for "no backend available"; "504 means the backend timed out" | 503 also when every attempt failed; 504 = connected backend silent or frontend timeout while waiting; connect timeout fails over | | #1806 | `bin/config.toml` `max_connection_attempts` | connect timeout always fails over | a TCP session whose connect times out is closed | | #1806 | `doc/debugging_strategies.md` | 503 after a circuit breaker of 3 failed connections; ERROR log lines, one that no longer exists | `max_connection_attempts` (default 5), `backend.connect.retries_exhausted`, real TCP log levels and text | | #1806 | `doc/configure.md` `front_timeout` / `connect_timeout` rows | "inactivity for a request to connect" | time to establish a backend connection; HTTP fails over, TCP closes; H1 failover bound by `front_timeout` | | #1806 | `doc/configure.md` `client_timeout_during_response`, `backend_timeout`, `http.503.errors` | "connection-level slowness", "circuit breaker" | failover case included; established connection only; attempt budget | | #1806 | `LIFECYCLE.md` backend timer | 504 for any linked stream | established connection only | | #1806 | `cli.rs` help, `doc/configure_cli.md` | "answered 503" | "or a TCP session is closed" | | #1756 | `doc/configure.md` flood metrics | RST lifetime rows described as absolute ceilings; no `window_update_stream0_window` row | floor-and-ratio semantics; row added | | #1756/#1798 | `doc/architecture.md`, `doc/h2_mux_internals.md` | 6 / 13 `H2FloodConfig` thresholds | 14, with `h2_stream_refusal_percent` | | #1756 | `doc/configure_admin_ops.md` | "halve" example 50/25 (old defaults); H2 knobs HTTPS only | 1000/500; HTTP and HTTPS; `h2.flood.stream_refused` | | #1752 | `doc/configure.md` glitch tuning | "1 MiB window ... about 64" frames | 64 KiB stream window, about four | | #1805 | `doc/health_checks.md` | `remove` resets backends to healthy; DOWN logs an error; `load_balancing.rs::BackendList::healthy` | backends keep their last state (see note); warning; `BackendList::select_tiers` in `backends.rs` | | #1805 | `doc/metrics.md` | health-check counters "per cluster" | unlabelled | | #1805 | `doc/configure_cli.md` | no health-check section | short section, `--mode`, `--probe-timeout` vs global `--timeout` | | #1746 | `cli.rs` `--load-balancing-policy`, `bin/config.toml`, proto comment | HRW/MAGLEV key = UDP flow key | UDP affinity key (source IP, or IP and port) | | UDP | `doc/configure.md` | hot upgrade drains flows bounded by idle timeout; `udp.flows.evicted` reasons | soft-stop closes flows at once; listener removal/soft-stop/abort added | | #1770 | `doc/udp_simulation.md` | no per-source limits | in reconfig storms and the invariant list | | #1743 | `doc/lifetime_of_a_session.md` | keep-alive backend always reused | unless its backend was removed | | older | `command.proto` update messages | `h2_stream_shrink_ratio >= 1` | `>= 2`, as validated in `state.rs` | | #1806 | e2e shuffle-sharding doc comment | "three connection attempts" | `max_connection_attempts` (5 by default) | Reported here, not changed in this PR: - `sozu cluster health-check remove` does not reset backends a probe marked DOWN (`remove_health_check_state` skips the reset that `set_health_check_config(None)` does), so they stay out of rotation until the cluster is added again. The doc now describes this. It looks like a code bug. - `sozu top`'s H2 pane reads `h2.flood.violation.{rapid_reset,made_you_reset,ping,settings,priority,continuation}`, which the detector never emits (it emits `rst_stream_pre_response_lifetime`, `ping_window`, ...). Only `glitch_window` matches, and `h2.flood.stream_refused` is not shown. - `h2_flood_detector.rs` comments still refer to a 1 MiB connection window, and the `h2_stream_idle_timeout_seconds` proto comment says "Default: 30" where the value inherits `back_timeout`. - `connections.rejected_per_cluster_ip` is documented as also counting TCP rejections; only the HTTP 429 path increments it. Validation: - `sozu config check` passes on `bin/config.toml`, on a copy with every commented key under review uncommented (global and cluster `max_connection_attempts`, the H2 block, the health check block), and on `os-build/config.toml` with local state/socket paths. Negative controls (`max_connection_attempts = 0`; `expected_status = 200` next to `accepted_statuses`) are rejected. - `cargo +1.93.1 test -p sozu-command-lib --all-features --locked`: 235 passed. - `cargo +1.93.1 test -p sozu --bin sozu --locked`: 124 passed (including the `--load-balancing-policy` help tests). - `cargo +nightly fmt --all --check` and `python3 .github/scripts/check_doc_citations.py --root . --base origin/main` are clean. Signed-off-by: Florentin Dubois <[email protected]>
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.
Fixes #1735
What changes
The mux pool-reuse scan (
Router::decide_after_gate) matched a pooled backend connection by cluster id only. A cluster id survivesRemoveCluster+AddClusterof the same id, and a cluster survivesRemoveBackend, so a new request could reuse a connection to a backend that is no longer configured.BackendList::remove_backendandBackendMap::remove_clustermark every backend they dropClosing.BackendRegistry::is_retired, passed to the core asRoutingView::with_backend_retired; the scan skips a connection whose backend is retired. Such a connection drains the streams it carries and takes no new one.Docs:
lib/src/protocol/mux/LIFECYCLE.md, CHANGELOG (Unreleased, Fixed).doc/testing.md: a line citation that drifted is replaced by its symbol.Tests (both seen red without the fix)
e2e:test_readded_cluster_does_not_reuse_removed_backendlib/src/backends.rs:removing_a_backend_or_its_cluster_marks_it_closinga_request_on_a_reused_backend_connection_allocates_nothingnow measures the reuse decision with the retired check.Validation
cargo +nightly fmt --all --checkcargo +1.93.1 clippy --all-features --all-targets --locked -- -D warningsRUSTDOCFLAGS="-D warnings" cargo doc --all-features --no-depscargo test --all-features --workspace --exclude sozu-e2ecargo test -p sozu-e2e --all-features --locked -- remove_cluster_tests mux_tests keep_alivecargo +nightly fuzz buildcheck_doc_citations.py(--self-test,--root .,--root . --base origin/main,--audit --root .)