Repository navigation
fix(command): earliest-deadline poll, cancelled-task routes, stopping-worker close - #1838
Merged
Merged
Conversation
The main-process event loop computed its poll timeout from the latest deadline of the pending tasks. A silent worker produces no readiness, so with two worker-backed commands pending, the one due first was only reaped, and its client only answered, once the later deadline expired. CommandHub::next_poll_timeout now selects the earliest outstanding deadline. poll_wakes_up_for_the_earliest_task_deadline pins it with two tasks held by a silent worker (deadlines 50 ms and 60 s). Fixes #1826 Signed-off-by: Florentin Dubois <[email protected]>
Server::cancel_task dropped the queued task but left its in_flight routes. A late worker answer or a worker closing then resolved to the cancelled task, found no task, and returned before any cleanup, so every state replay load_state abandons on a parse error leaked its routes for the life of the main process. Cancellation now retires every route belonging to the cancelled task and keeps the routes of other tasks. cancelling_a_task_retires_only_its_response_routes pins it, including a late answer and a worker closure after cancelling. Fixes #1827 Signed-off-by: Florentin Dubois <[email protected]>
UpgradeData carries no client, task or worker-response route, and the old main process stops reading worker answers once the handoff is confirmed, so a command admitted before the upgrade had no continuation and its client was never answered. upgrade_main now refuses while CommandHub::pending_task_count is non-zero. The requesting client receives an immediate Failure naming the number of pending commands, before any side effect: no boot_generation bump, no MainUpgraded audit success, no fork. The pending commands complete normally and the operator retries. The contract is documented in doc/configure_cli.md and bin/src/command/LIFECYCLE.md, and pinned by upgrade_main_is_refused_while_a_control_command_is_pending, which holds a worker answer across the upgrade request. Fixes #1832 Signed-off-by: Florentin Dubois <[email protected]>
The old worker of an upgrade --worker is marked Stopping, then its SoftStop answer is awaited by a task with no deadline. The close path synthesised failures only for an active worker, so a Stopping worker that closed before answering left that task unfinished forever, and every later upgrade-main was refused as pending until the main process restarted. Synthesise the failures on the first close of any worker that is not yet Stopped, which still prevents double counting on a repeated CloseSession, and stop counting tasks that already gathered every answer as pending. Signed-off-by: Florentin Dubois <[email protected]>
Signed-off-by: Florentin Dubois <[email protected]>
Signed-off-by: Florentin Dubois <[email protected]>
upgrade_main refused to hand over while CommandHub::pending_task_count was non-zero. That breaks the main-upgrade-during-drain contract pinned by main_upgrade_keeps_a_draining_worker_serving_its_requests (bin/tests/upgrade_keeps_draining_worker_e2e.rs): an upgrade --worker whose old worker is still draining keeps a Timeout::None SoftStop task pending, so the main upgrade was refused. Pending control commands are to be transferred to the new main process instead, which issue #1832 tracks separately. Remove the refusal from upgrade_main, the pending_tasks parameter of Server::handle_client_request, CommandHub::pending_task_count (no other caller), the test-helper visibility widening it needed, and the refusal documentation in doc/configure_cli.md, bin/src/command/LIFECYCLE.md and CHANGELOG.md. The test upgrade_main_is_refused_while_a_control_command_is_pending is deleted deliberately: it pinned the refusal contract that this commit withdraws, so it no longer describes intended behavior. No check is silenced; the e2e above passes again. The earliest-deadline poll (#1826), the cancelled-task route retirement (#1827) and the Stopping-worker close fix stay. The latter's test is renamed a_stopping_worker_closing_finishes_its_pending_task and now asserts that the task finishes with one synthetic failure and that in_flight is empty, with no reference to the withdrawn refusal; its CHANGELOG entry stands alone. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 4, 2026
The main-process hot upgrade rebuilt an empty command Hub while worker work could still be in flight. The original command client then received EOF, and a later worker response reached the replacement as an unknown task even though its data-plane request could still finish. This change transfers the complete control-plane ownership graph to the replacement main: connected clients, client and worker channel buffers, active and queued tasks, worker-response routes, subscribers, worker pending queues, stopped workers still referenced by a task or route, task deadlines, audit clocks, and future-ID counters. The replacement restores task state directly without replaying operator requests or re-scattering work. The handoff uses an explicit V2 `PREPARED` / `COMMIT` / `ACTIVATED` protocol: - the replacement validates and registers inherited descriptors while paused, without command or worker data I/O; - pre-commit rejection closes and reaps the candidate, restores `CLOEXEC`, and lets the unchanged old Hub continue; - the first attempt to send `COMMIT` irreversibly fences the old Hub, so an ambiguous post-commit failure cannot execute work twice; - after a complete commit, the replacement activates the Hub, schedules restored sessions once, publishes PID and systemd readiness, preserves the initiating client's terminal response under backpressure, and acknowledges activation before the old main exits. Compatibility fails closed before adoption. A running main from before this protocol cannot export the missing Hub state, so the first deployment requires a controlled service restart after pending commands are drained and state is saved. Subsequent V2-to-V2 hot upgrades transfer pending commands. A V2 sender rejects a legacy candidate before freezing live ownership; a legacy sender remains subject to its existing generation, audit, and child-reaping limitations when a V2 candidate refuses its old envelope. `SIGTERM` observed before commit aborts and reaps the candidate, then the old event loop consumes the preserved stop intention. Operators should signal the service control group. A signal aimed only at the old PID after the final pre-commit observation remains outside this contract, and a failure after commit is fail-stop rather than crash recovery. The branch is based on `9561b24e61c23511326ffeb547b0b7fe51ee7055`, including the deadline and cancelled-route fixes from #1838 and the PROXY protocol corrections merged in #1844. Channel snapshot validation accepts all five defined `Ready` bits in both serialized readiness and interest, preserves them exactly, and rejects the first unknown bit `0x20`. This covers the Linux readiness word `WRITABLE | HUP | WRITE_CLOSED` (`0x001a`) without special-casing that observed value. Descriptor-cleanup tests observe the original command-channel and SCM socket peers instead of probing released numeric descriptors or requiring immediate EOF. EOF is the only success outcome within a fixed one-second bound: data, other errors, and expiration fail. This tolerates transient descriptor copies across a concurrent fork-to-exec window while retaining a durable duplicate of either endpoint still fails the test. The exact transient holder in the original CI jobs was not instrumented, so that scheduler-level cause remains unverified. Validation completed locally with Rust 1.93.1 and at most four build jobs: - `cargo test -p sozu-command-lib --locked`: 244 unit tests, 9 integration tests, and 2 doctests passed; 3 existing doctests were ignored. - `cargo test -p sozu --locked --test upgrade_fd_inheritance_e2e -- --ignored`: failed 0/1 on the earlier snapshot mask with `invalid channel snapshot readiness bits: 0x001a`, then passed 1/1 after accepting `WRITE_CLOSED`. - the snapshot regression exercises all 32 subsets of the five defined bits in both readiness and interest; it rejects `0x20` in each field. Removing `WRITE_CLOSED` makes the test fail on `0x10`. - `cargo test -p sozu --locked --no-default-features --features crypto-openssl,opentelemetry,splice,simd --verbose`: 152/152 library tests passed and every integration and doctest target completed successfully. - `cargo test -p sozu --locked --no-default-features --features fips,opentelemetry,splice,simd --verbose`: 152/152 library tests passed and every integration and doctest target completed successfully. - retaining durable duplicates of both the command channel and SCM endpoint makes each corrected cleanup oracle fail with both EOF deadlines; restoring the candidate makes each targeted test pass 1/1. - the accepted-handoff, rejected-candidate, SIGTERM-during-PREPARE, and descriptor-inheritance process tests pass 1/1 on the rebased head. - the compatibility matrix passes 1/1 in both directions between the rebased candidate and the frozen pre-protocol `d7b5f14d` binary. This verifies those two transition paths rather than certifying every historical version pair; the legacy generation, audit, and child-reaping limitations described above remain observable. - `cargo clippy --all-targets --locked --no-default-features --features crypto-openssl,opentelemetry,splice,simd -- -D warnings` and the equivalent FIPS matrix passed. - `cargo +nightly fmt --all --check` passed. - `.github/scripts/check_doc_citations.py --base 9561b24` passed all 37 citations, 1,078 test names, and 15 pinned excerpts. - `env -u RUST_LOG ... cargo +1.93.1 test -p sozu --locked --features opentelemetry,splice,simd --test sigterm_soft_stop_e2e -- --ignored`: 1/1 passed. The local 27/27 missing-access-log result was caused by ambient `RUST_LOG=warn`, which GitHub CI does not set; the test requires its configured `info` access records. GitHub CI checks are pending on the rebased commit `a8bdd54b8833060576674a8c2aff0374f6e8083b`. Fixes #1832 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.
Three fixes in the main-process command hub (
bin/src/command/).Fixes #1826
Fixes #1827
#1832 (pending control commands across
upgrade-main) is not addressed here. It is handled separately by a design that transfers pending control commands to the new main process. An earlier revision of this PR refusedupgrade-mainwhile a command was pending; that refusal has been withdrawn (see below).#1826: the command poll sleeps until the latest task deadline
CAUSE:
CommandHub::run(bin/src/command/server.rs) selected the poll timeout with.max()over the pending task deadlines. A silent worker produces no readiness, so the earlier task was only reaped when the later deadline expired, and its client was answered late.Fix:
CommandHub::next_poll_timeoutuses the earliest outstanding deadline (.min()).Test:
poll_wakes_up_for_the_earliest_task_deadline. Two tasks are scattered to a worker that never answers, with deadlines of 50 ms and 60 s. The test asserts the poll timeout is at most 50 ms. RED onorigin/mainsemantics (.max()):the loop must wake up by the earliest deadline (50ms), got 59.999554694s. This test pins the timeout computation itself. It does not run the infiniterunloop against the wall clock: the sweep at the top of that loop already reaps any task whose deadline has passed.#1827: cancelling a control task leaves its worker-response routes
CAUSE:
Server::cancel_taskremoved the task fromqueued_tasksonly, so itsin_flightroutes survived. A late worker answer, orfail_in_flight_requests_of_workerafter a worker closed, then found the route, found no task, and returned early inhandle_worker_responsebefore any cleanup. Each state replay thatload_stateabandons on a parse error (the only caller) leaked its routes.Fix:
cancel_taskalso retires everyin_flightroute of the cancelled task and keeps the routes of other tasks. This matches the purgehandle_finishing_taskalready does.Test:
cancelling_a_task_retires_only_its_response_routes. It cancels one task that has 2 routes while a second task with 1 route is pending, then sends a late answer to the cancelled task and closes a worker. RED:left: [("1-0-1", 0), ("0-1-1", 1), ("0-0-1", 0)] right: [("0-1-1", 1)].A stopping worker that closes answers its in-flight commands
CAUSE:
upgrade --workermarks the old workerStopping, then waits for itsSoftStopanswer in a task with no deadline (Timeout::None). The worker-close path synthesised failures only for anis_activeworker, whichStoppingis not. AStoppingworker whose channel closed before it answered left that task, itsin_flightroute and its client waiting until the main process restarted.Fix:
CommandHub::on_worker_channel_closedsynthesises the failures on the first close of any worker that is not yetStopped. A repeatedCloseSessionof the same session, nowStopped, still synthesises nothing, so nothing is double-counted.Test:
a_stopping_worker_closing_finishes_its_pending_task. AStoppingworker holds aSoftStopin aTimeout::Nonetask and closes twice. The test asserts thatin_flightis empty, the task has finished, and it accounts exactly one failure(0, 1, 1). RED with theis_activegate restored: the task stays unfinished (panic at thehas_finishedassertion).Withdrawn: the upgrade-main refusal
The refusal (
upgrade_mainfailing whileCommandHub::pending_task_countwas non-zero) broke the #1668 e2emain_upgrade_keeps_a_draining_worker_serving_its_requests(bin/tests/upgrade_keeps_draining_worker_e2e.rs). A main upgrade while a worker is still draining afterupgrade --worker 0must succeed, and the draining worker'sSoftStoptask kept the upgrade refused. The refusal,pending_task_count, its test, and its documentation indoc/configure_cli.md,bin/src/command/LIFECYCLE.mdandCHANGELOG.mdhave been removed. The test that pinned the refusal was deleted because the behavior itself is withdrawn; no check was silenced.Validation
cargo test -p sozu -p sozu-command-lib --all-features --locked-> exit 0 (150 bin tests, 237 command-lib tests, all passed)cargo test -p sozu --all-features --test upgrade_keeps_draining_worker_e2e -- --ignored->main_upgrade_keeps_a_draining_worker_serving_its_requests ... okcargo clippy --all-features -p sozu -- -D warnings-> exit 0cargo +nightly fmt --all --check-> exit 0python3 .github/scripts/check_doc_citations.py --root . --base origin/main-> exit 0