Repository navigation
fix(backends): preserve backend identity and incarnation; document SetHealthCheck's draining boundary - #1839
Merged
Conversation
…al and health checks AddBackend and ConfigState identify a backend by (backend_id, address) and admit two ids at one address, but the worker dropped that identity: - RemoveBackend removed every backend at the address, so removing id A answered ok while its sibling B, still listed by ConfigState, stopped receiving traffic; - HTTP/TCP and UDP health results were applied to the first backend at the probed address, so a failed probe of B marked A DOWN; - a probe in flight when its backend was removed could complete after the same id and address were added again and mark the new backend DOWN. BackendList::remove_backend and BackendMap::remove_backend now take the backend id and remove only the backend with that id at that address. Each HTTP/TCP and UDP probe captures a Weak handle on the backend it was launched for and applies its result only while that entry is still in the cluster's list, so a result for a removed incarnation is discarded and never lands on a sibling or on a re-added replacement. In-flight deduplication is per incarnation, so the replacement is probed on the next cycle. RemoveCluster still drops the whole cluster list. Fixes #1821 Signed-off-by: Florentin Dubois <[email protected]>
…y boundary SetHealthCheck validates and stores the replacement policy and acknowledges it without cancelling the probes already in flight. Each InFlightCheck captured its mode and request, timeout, accepted statuses and thresholds at launch, so it completes under the old policy and can still change a backend's health after the acknowledgement; only probes launched afterwards use the new policy. Updating a policy launches no probe and keeps the last launch time, so the new interval counts from it. Document that boundary in doc/health_checks.md and pin it with a real-socket e2e test: two HTTP probes in flight finish with the old accepted status and failure threshold after a TCP policy is acknowledged, then a later probe uses TCP mode and the new threshold. The file's set_health_check helper now returns the worker's answer to the request it sent. No behaviour change. Fixes #1824 Signed-off-by: Florentin Dubois <[email protected]>
The HTTP and UDP health checkers skip a backend while a probe is in flight for the same backend incarnation, so a probe still draining for a removed backend never delays the first probe of a replacement re-added with the same id and address. No test held that: comparing in-flight probes by backend id again passed the whole suite. Two unit tests now launch a real probe, remove and re-add the backend, and assert the replacement is probed on the next cycle. BackendMap::remove_backend now logs a warning when the cluster exists but no backend matches the requested (id, address), and the hash_backend comment no longer claims the address is the removal key. The CHANGELOG notes that a RemoveBackend with a mismatched id now removes nothing. Signed-off-by: Florentin Dubois <[email protected]>
…and-health-policy Signed-off-by: Florentin Dubois <[email protected]>
Signed-off-by: Florentin Dubois <[email protected]>
Signed-off-by: Florentin Dubois <[email protected]>
This was referenced Oct 4, 2026
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 4, 2026
…1856) * fix(load-balancing): give a shared address the share of one backend Two backend ids at one address are distinct backends since #1839 (identity `(backend_id, address)`), but only HRW gave their address the share of one endpoint: round robin, random, least loaded, power of two and Maglev gave it one share per id (A,B@X + C@Y, equal weights: X took about 2/3 of the selections instead of 1/2). `BackendList` now hands every policy one candidate per address, after the tier, retry-exclusion and shard filters. The representative is the heaviest eligible id, the first in list order among equal weights (`outranks_at_address`), which is exactly the id HRW already picked, so HRW is unchanged and a down or backing-off id never hides an eligible sibling. The address weighs what its representative weighs. Maglev builds one table entry per distinct address, weighted by the heaviest of its ids. Shuffle sharding ranks and counts distinct primary addresses and puts every primary id of a selected address in the shard. A list without a shared address skips the collapse (flag maintained on the control plane); with one, the collapse is a quadratic scan of the candidates into a reserved scratch buffer, without allocating. Signed-off-by: Florentin Dubois <[email protected]> * fix(load-balancing): assert the shared-address flag in the list invariants check_invariants now recomputes shares_address and asserts it matches, so a backend-list mutation that bypasses add_backend/remove_backend fails loudly instead of silently skipping the collapse. The CHANGELOG entry links #1856 and states that the keyless round-robin fallback of HRW and Maglev collapses too. Signed-off-by: Florentin Dubois <[email protected]> * perf(load-balancing): link same-address ids on the control plane The collapse compared every candidate with every other one and the shard ranking re-derived each address's representative by scanning the list, so one shared pair put every selection of the cluster on a quadratic path (release, round robin, 1000 backends: 3.9 us -> 2.5 ms). `refresh_siblings` now builds, on every list or configuration mutation, a sibling ring linking the ids of each address and each id's shard rank. The collapse walks only the rings of candidates that have a sibling, looking siblings up among the candidates by binary search, and compute_shard reads the precomputed ranks and walks rings to take in a shared address's other ids. A list without a shared address selects exactly as before; one with a shared pair is back to linear (1000 backends: 5.2 us). A test counts the shared-address work per selection and fails on a per-candidate scan. LEAST_LOADED and POWER_OF_TWO now compare an address's load as the sum of its ids' connection or request counts, walked through the same ring (`Candidates::siblings`), without allocating; CONNECTION_TIME still reads the representative's own average. Signed-off-by: Florentin Dubois <[email protected]> * fix(load-balancing): tolerate a directly edited backend list `BackendList.backends` is public, so a library user may push or pop a backend without add_backend/remove_backend, leaving the sibling state of another length. The collapse is now skipped and compute_shard ranks every primary as its own address when that state's length differs from the list, and Candidates::with_siblings ignores a ring of another length, so a selection never indexes it out of bounds. Lists kept in sync select exactly as before. State the cost bound precisely: linear in the candidates plus, per shared address of g ids, up to g² ring steps (refresh_siblings: linear plus g² per shared address). Public docs of Candidates and Maglev no longer link the private outranks_at_address, which failed cargo doc under -D warnings. Signed-off-by: Florentin Dubois <[email protected]> --------- 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.
Two commits, one per issue. They touch the same files (
lib/src/backends.rs,lib/src/health_check.rs,lib/src/udp/health.rs,lib/src/server.rs).fix(backends): keep backend identity and incarnation through removal and health checks (#1821)CAUSE (removal):
lib/src/backends.rs:1398BackendList::remove_backendmatched on address only ->BackendMap::remove_backend(backends.rs:749) ->Server::remove_backend(server.rs:2974) -> SYMPTOM: removing id A also removed same-address sibling B from the worker. The e2e test showedsame-address sibling reached: false; response after targeted removal: None, whileConfigState(keyed on(backend_id, address),command/src/state.rs:2255) still listed B.CAUSE (results):
lib/src/health_check.rs:598/lib/src/udp/health.rs:517find_backend(&address)-> the result went to the first backend at the probed address, and to whatever backend was live at that address when it completed -> SYMPTOM: a failed probe of B marked A DOWN, and a probe started before a remove completed after the same id/address was re-added and marked the new backend DOWN.Fix:
BackendList::remove_backend(backend_id, address)andBackendMap::remove_backend(cluster_id, backend_id, address)remove only the matching(backend_id, address)entry and returnbool.Server::remove_backendpasses the requested id. Metrics cleanup is still keyed on the requested id.InFlightCheckand UDPInFlightProbeholds aWeak<RefCell<Backend>>to the backend it was launched for.record_check_resultandUdpHealthChecker::recordapply a result only if that exact entry is still in the cluster's list (BackendList::find_incarnation, a pointer comparison that is safe because theWeakkeeps the allocation alive, so it cannot be reused). A result for a removed backend is dropped. A re-added backend is a new entry: it starts healthy, and the next cycle probes it, because duplicate in-flight probes are now detected per entry rather than perbackend_id.RemoveClusterstill removes the whole cluster:cluster_removal_requestssends oneRemoveBackendperConfigStatebackend with its realbackend_id(command/src/state.rs:735-748), andremove_cluster_objectsthen callsBackendMap::remove_cluster(server.rs:2956).test_remove_cluster_stops_http_routing,…_tcp_routingandtest_readded_cluster_does_not_reuse_removed_backendpass.BackendMap::close_backend_connectionandBackendMap::has_backendstill look backends up by address. Neither has a caller in the tree outsidebackends.rsdebug assertions. The remainingfind_backendcall outsidebackends.rsis a router test.doc/health_checks.md(How it works),doc/configure.md(UDP health),doc/configure_cli.md(backend remove). CHANGELOG under Fixed, marked BREAKING (library API) because the publicremove_backendsignatures changed.docs(health-check): SetHealthCheck's draining policy boundary (#1824)There is no production change: the behaviour is intended.
doc/health_checks.mdnow says thatSetHealthCheckacknowledges the new policy without cancelling probes already in flight. Those probes finish under the policy they captured at launch, only later probes use the new one, and the next probe is scheduled from the existing last launch time. The real-socket e2e testin_flight_probe_finishes_with_old_policy_then_future_probe_uses_new_policypins this. The file'sset_health_checkhelper now returns the worker's answer to the request it sent instead of draining all answers. The wholehealth_check_mode_testsmodule was re-run. CHANGELOG under Changed.Red / green evidence
origin/main(bd19a78), with the audit's prepared tests:health_check::tests::late_result_after_remove_and_readd_same_identity_does_not_mutate_replacementfailed: "a late result from the removed generation must not mark its replacement DOWN".udp::health::tests::probe_result_updates_the_backend_id_that_was_probedfailed:left: (false, true) right: (true, false).test_removing_one_backend_id_keeps_same_address_siblingfailed: sibling not reached, responseNone.record/remove_backendsignatures changed. Instead they were shown red with a mutation that restores the pre-fix address lookup infind_incarnation: all four failed (health_check+udp::health× {sibling, late result after remove/re-add}). The late-result tests also hold a strongRc, as a session would, and include a positive control: a result for the live backend does apply.SetHealthCheckcallhealth_checker.remove_cluster(cancelling in-flight probes) fails it withNotConnectedathealth_check_mode_tests.rs:580.MUTATIONmarker from this change.Validation (toolchain 1.93.1)
cargo +nightly fmt --check-> exit 0cargo +1.93.1 clippy --all-features --all-targets --locked -- -D warnings-> exit 0, 0 warningsRUSTDOCFLAGS="-D warnings" cargo +1.93.1 doc --no-deps --locked -p sozu-lib -p sozu-command-lib -p sozu-> exit 0cargo +1.93.1 test -p sozu-lib --lib --all-features --locked->test result: ok. 1597 passed; 0 failedcargo test -p sozu-e2e --locked --features opentelemetry,splice,simd -- --test-threads=1 tests::health_check_mode_tests:: tests::remove_cluster_tests::->test result: ok. 11 passed; 0 failedtests::metrics_lifecycle_tests::,tests::tests::test_http_behaviorsandtests::tests::test_blue_greenall passed.python3 .github/scripts/check_doc_citations.py --root . --base origin/main-> exit 0test_remove_health_check_restores_down_backendfailed once. Its precondition request got a clientEAGAINwhile the shared host was at load average 65–86 (success=1 failure=1 down=1). It then passed 3/3 in isolated runs and again in the second full-module batch. It does not involve backend removal.Fixes #1821
Fixes #1824