Skip to content

fix(command): roll back unacknowledged replay entries and bound the load-state fan-out (#1313) - #1325

Merged
FlorentinDUBOIS merged 3 commits into
mainfrom
fix/load-state-rollback
Sep 15, 2026
Merged

FlorentinDUBOIS merged 3 commits into
mainfrom
fix/load-state-rollback

Conversation

@FlorentinDUBOIS

@FlorentinDUBOIS FlorentinDUBOIS commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1313 — the rollback half left open after #1315, plus the "no responses at all" hang reported in the issue thread.

Cause

LoadState (sozu state load) and ReloadConfiguration dispatched every saved entry into the main ConfigState before the fan-out and judged the whole batch by one fleet-wide ok/errors tally: LoadStateTask::on_finish never touched server.state, so an entry every worker rejected stayed in the master state, was re-persisted by SaveState and re-injected on every replay. The live single-request path has had a unanimous-rejection rollback since #1302/#1316; the replay paths had none.

Both load paths also scattered with Timeout::None, and three accounting holes could keep ok + errors short of expected_responses forever: a request the master could not write to a worker channel was dropped while still counted as expected; a worker closed with requests in flight answered nothing; and a state file larger than the worker back buffer (max_command_buffer_size, 2 MB) had its entries refused frame by frame. Any of them left the task, and the CLI waiting on it, without an answer.

Fix

  • Per-entry rollback: PerEntryGatherer attributes every worker answer to its replay entry through the scatter id {worker_id}-{task_id}-{request_index}, captures compute_rollback at scatter time, and on_finish reverts exactly the entries no worker acknowledged under the existing should_rollback_fanout predicate. An entry at least one worker acknowledged is never reverted. Applied to LoadStateTask and LoadStaticConfigTask.
  • Bounded deadline: one worker_timeout plus 10 ms per scattered entry, capped at ten worker_timeouts, re-armed after parsing; a timeout is reported to the client as a failure and audited with error_code=worker_timeout.
  • Synthetic failures: a request that cannot be queued on a worker and every request still in flight on a closing worker count as Failure for the owning task (the live WorkerTask benefits too). An answered request leaves the in-flight map immediately, so a worker that answers and then dies does not turn a successful replay into a failed one.
  • Non-blocking backpressure: WorkerSession parks what does not fit in a per-worker pending queue and drains it in order from the event loop's writable path. The supervisor never blocks on a worker socket; the buffer ceiling is unchanged.

Tests

  • bin/src/command/requests.rs load_state_rollback_tests and bin/src/command/server.rs tests: per-entry revert, timed-out replay, attribution, unqueued-request accounting, worker-close accounting without double counting, 500-entry scatter through a 4 KiB ceiling delivered in order. All seen red before the fix (recipes in the module docs).
  • bin/tests/load_state_rollback_e2e.rs (#[ignore], run with -- --ignored): replays a state file carrying a frontend on an address with no listener against a real master with one worker, then asserts state save no longer contains it and that state load answered within a bounded time.
  • bin/tests/load_state_rollback_e2e.rs also replays a state file larger than max_command_buffer_size (lowered to 16 KiB in the test config): state load answers within its deadline, the master log shows no refused entry, the saved state holds all 200 frontends and the worker routes the last one (seen red with the pending queue disabled); and a mixed file keeps its accepted entries, drops the rejected one and reports reverted entries: 1.
  • Every load-path refusal is logged: warn! when ConfigState refuses an entry (both load paths, counted with the validation skips) and one warn! per worker rejection with worker id and entry index.
  • .github/workflows/ci.yml gains cargo test -p sozu and a Test sozu (process-level e2e) step running the three bin/tests/*_e2e.rs suites with -- --ignored; before it they ran nowhere. sozu_top_e2e stays out: it needs the tui feature no matrix cell enables.

Verification

cargo +nightly fmt --all -- --check                                                   -> exit 0
rustup run 1.93.1 cargo clippy --workspace --all-targets --all-features --locked -- -D warnings -> exit 0
cargo test -p sozu --locked                                                           -> 88 passed
cargo test -p sozu --locked --test load_state_rollback_e2e -- --ignored               -> 1 passed
cargo test -p sozu-command-lib --locked / cargo test -p sozu-lib --locked             -> all passed

Docs updated in the same change: CHANGELOG.md, bin/src/command/LIFECYCLE.md, doc/observability.md.

Known residual: UpgradeWorkerTask still uses Timeout::None; it now benefits from the synthetic-failure accounting but keeps no deadline, out of scope here.

…oad-state fan-out (#1313)

`LoadState` and `ReloadConfiguration` dispatched every saved entry into the
main `ConfigState` before the fan-out and judged the whole batch by one
fleet-wide ok/errors tally, with no rollback: an entry every worker rejected
stayed in the master state, was re-persisted by `SaveState` and re-injected on
every replay. Both load tasks now gather per entry, attribute worker answers by
the scatter id `{worker_id}-{task_id}-{request_index}`, and revert each entry
no worker acknowledged with the inverse `compute_rollback` computed at scatter
time, under the same `should_rollback_fanout` predicate as the live path.

The same paths could also hang forever with no answer to the client: they
scattered with `Timeout::None`, a request that could not be written to a worker
channel was dropped while still counted as expected, a worker closed with
requests in flight answered nothing, and a large state file overflowed the
worker back buffer frame by frame. Undeliverable requests and the in-flight
requests of a closing worker are now accounted as `Failure`, an answered
request leaves the in-flight map immediately, a per-worker pending queue drains
the overflow from the event loop's writable path without blocking the
supervisor, and both load tasks arm a bounded deadline scaled by the entry
count and reported as a failure.

Unit tests in `bin/src/command/{requests,server}.rs` were seen red before the
fix; `bin/tests/load_state_rollback_e2e.rs` replays a poisoned state file
against a real master. CI now runs `cargo test -p sozu`.

Closes #1313

Signed-off-by: Florentin Dubois <[email protected]>
A replay entry that ConfigState refuses was skipped silently on both load
paths, and a worker Failure only bumped a counter. At startup there is no
client to carry the reason, so the log line is the only trace: warn on the
dispatch refusal, count it with the validation skips, and warn once per
worker rejection with the worker id and entry index.

Signed-off-by: Florentin Dubois <[email protected]>
…ocess-level suites in CI

Replay a state file larger than max_command_buffer_size against a real
master and worker: the load answers within its deadline, no entry is
refused by the worker channel, the saved state holds every frontend and
the worker routes the last one. A mixed file keeps its accepted entries,
drops the rejected one and reports the reverted count. The three
bin/tests/*_e2e.rs suites stay #[ignore]d for a fast local cargo test and
now run from a dedicated CI step; before it they ran nowhere.

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit e073db5 into main Sep 15, 2026
23 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the fix/load-state-rollback branch September 15, 2026 14:15
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.

LoadState replay has no rollback: a poisoned saved state re-injects rejected entries forever

1 participant