Skip to content

fix(command): roll back a fanned-out change when the scatter times out unacknowledged - #1316

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/rollback-on-unanimous-timeout
Aug 27, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/rollback-on-unanimous-timeout

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Problem

The #1301 unanimous-rejection rollback in WorkerTask::on_finish only fired on !timed_out && expected > 0 && ok == 0 && errors > 0 — it required at least one worker to actually answer Failure. A worker that panics never answers at all: close_worker/handle_worker_close mark it Stopped without injecting a synthetic Failure and without decrementing expected_responses, so has_finished (ok + errors >= expected) never becomes true and the task can only end through the scatter's own timeout branch, which reports timed_out=true. In that shape errors > 0 is never satisfied, the rollback never fires, and a malformed frontend that every worker effectively rejected (one by panicking, one silently) stays committed in the main process's ConfigState forever — SaveState re-persists it on every subsequent save, even though the client was already told the command failed.

Fix

Extracts the rollback decision into a small, exhaustively-tested pure predicate and widens its trigger to cover both ways a fan-out can end with zero acknowledgements:

fn should_rollback_fanout(timed_out: bool, expected: usize, ok: usize, errors: usize) -> bool {
    expected > 0 && ok == 0 && (errors > 0 || timed_out)
}

Both the revert and the non-revert error log lines were also corrected to report counts only (ok=0, errors=N, expected=M, timed_out=bool), never request content — the #1301-era strings claimed "after all worker(s) rejected it", which stopped being accurate once the timeout path could reach the same branch. A few stale doc-comments describing the old "unanimous rejection" trigger were updated to match.

Residual behaviour, documented in the code: a slow-but-healthy worker whose Ok arrives after the deadline is invisible to the already-finished task, so it keeps the frontend locally while the main process reverts. This is a bounded divergence — it self-heals on that worker's next restart or state replay, and it matches the failure already reported to the client.

Tests

Six exhaustive unit cases for the extracted predicate (rollback_predicate_tests): a clean fan-out (never rolls back), a local-only fan-out (never rolls back), any acknowledgement present (never rolls back regardless of timeout), unanimous rejection (rolls back — #1301, unchanged), a timeout with zero answers at all (rolls back — new), and a timeout with only failure answers (rolls back — new).

A real scatter timeout can't be unit-simulated (on_finish needs a live &mut Server and the deadline lives in the event loop), so the guarantee is composed of this predicate (the decision) plus the existing handle_finishing_task_forwards_timed_out_flag test (the propagation) — the same split #1301 used around compute_rollback.

RED — predicate first introduced as the exact pre-fix expression (!timed_out && expected > 0 && ok == 0 && errors > 0):

cargo test -p sozu --locked --lib rollback_predicate_tests
...
test rollback_predicate_tests::timeout_with_no_answer_at_all_rolls_back ... FAILED
test rollback_predicate_tests::timeout_with_only_failures_rolls_back ... FAILED
test result: FAILED. 4 passed; 2 failed; 0 ignored

Exactly the two timeout cases fail; the four cases matching pre-existing behaviour stay green.

GREEN — fix restored, same unmodified command:

cargo test -p sozu --locked --lib rollback_predicate_tests
test result: ok. 6 passed; 0 failed; 0 ignored

Commands run

  • cargo test -p sozu --locked → ok, 72 passed, 0 failed (plus the pre-existing #[ignore]d e2e test, untouched)
  • cargo clippy -p sozu --all-targets --locked -- -D warnings → clean
  • cargo +nightly fmt --all -- --check → clean

Notes

Based on #1312 — will be retargeted/rebased onto main once it merges.

Fixes #1314

…t unacknowledged

The unanimous-rejection rollback added for sozu#1301 was gated on
`!timed_out && expected > 0 && ok == 0 && errors > 0`, so it was skipped
whenever the fan-out ended through its timeout instead of through
`has_finished`. That guard assumed a rejecting worker answers, and a
panicking one does not: `handle_worker_close` marks the worker `Stopped`
without injecting a synthetic `Failure` and without decrementing
`expected_responses`, so `ok + errors >= expected` never becomes true and
the task can only end on the deadline. `errors > 0` therefore cannot
express "no worker took this change".

The consequence is the incident shape of sozu#1314: during a rolling
upgrade a single worker still running an unpatched build panics on a
malformed frontend hostname, the request times out, the revert is
skipped, and the malformed entry stays committed in the main process's
`ConfigState` — the authoritative state replayed into every restarted or
upgraded worker, and re-persisted by `SaveState` — even though the
operator was already told the command failed.

Extract the decision into `should_rollback_fanout(timed_out, expected,
ok, errors)` and widen it to `expected > 0 && ok == 0 && (errors > 0 ||
timed_out)`: revert on either trigger as long as NO worker acknowledged
the change. `ok == 0` remains the safety bound, so an entry at least one
worker applied is still never reverted and the main process never
diverges from the workers that accepted it. The rollback log lines carry
counts only — a `RequestHttpFrontend` rendering would leak the
operator-supplied hostname.

Accepted residual: a slow-but-healthy worker whose `Ok` lands after the
deadline is invisible to the finished task, so it keeps the frontend
until its next restart or state replay while the main process reverts. That
divergence is bounded, self-heals on replay, and matches the failure
already reported to the client — strictly better than permanently
committing an entry no worker confirmed.

`WorkerTask::on_finish` needs a real `&mut Server` and the deadline lives
in the event loop, so the guarantee is composed rather than simulated:
`handle_finishing_task_forwards_timed_out_flag` pins the propagation of
`timed_out` into `on_finish`, and the new `rollback_predicate_tests`
pin the decision that flag feeds. Same shape as sozu#1301, where only
`compute_rollback` is unit-tested.

Branches off the sozu#1312 frontend-hostname fix, which is what makes a
worker answer `Failure` instead of dying; this closes the timeout hole in
the sozu#1301 safety-net for every rejection class, including fleets that
are mid-upgrade.

Fixes #1314

Signed-off-by: Florentin Dubois <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unanimous-rejection rollback is skipped on scatter timeout, committing the rejected entry permanently

1 participant