Repository navigation
fix(command): transfer pending commands during main upgrade - #1846
Merged
Merged
Conversation
Signed-off-by: Florentin Dubois <[email protected]>
Signed-off-by: Florentin Dubois <[email protected]>
Released descriptor numbers can be reused by parallel tests, while inherited CLOEXEC copies can transiently delay EOF. Observe the original channel and SCM peers under a fixed bound so cleanup tests reject durable leaks without mistaking number reuse for retained ownership. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/upgrade-main-transfer-pending-commands
branch
from
October 4, 2026 01:09
0e9e651 to
a8bdd54
Compare
Collaborator
Author
|
Review of a8bdd54. Fix requested before merge. The transfer design checks out: descriptor ownership, rollback before COMMIT, deadlines carried as remaining time, no replay of partial P1 — a pid-file write failure after COMMIT takes the whole proxy down.
P2 — upgrade-main always fails when
P3:
Verification:
|
After COMMIT the old main is irreversibly fenced and exits whatever the replacement does, and every worker returns from its event loop once its command channel closes. `begin_new_main_process` restored close-on-exec, installed its SIGTERM handler and wrote the pid file only after COMMIT, so an unwritable pid file (or a failed handler install) stopped every process while the old main exited 0 and `Restart=on-failure` did not restart it. The replacement now restores close-on-exec on its paused Hub, installs its SIGTERM handler and opens its pid file without truncating it before PREPARED, where a failure still rolls back. After COMMIT only activation can fail, since restoring a worker's SCM socket changes a file description the old main shares; a pid-file write, terminal-response or ACTIVATED failure is logged and the new main keeps running. Pinned by the process-level `unwritable_pid_file_rolls_back_main_upgrade_and_keeps_serving`, added to the CI process-level e2e step. `prepare_from_upgrade_data` also expected every client channel to start at `CLIENT_CHANNEL_INITIAL_BUFFER_SIZE`, while `Channel::new` clamps it to `max_command_buffer_size` (#1416), so a ceiling below 4096 bytes made every main upgrade fail; it now expects the clamped value, pinned by `prepare_from_upgrade_data_accepts_clamped_client_channel_capacity`. The compatibility matrix skips with a message when its frozen binaries are not configured instead of panicking the whole `--ignored` run, and stale `CommandHub::from_upgrade_data` / `SerializedWorkerSession::try_from` references name the current symbols. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 4, 2026
…1848) Follow-up to #1846 (merged as 7e2ebc0). ## Problem 1. A SIGTERM delivered to the whole cgroup while the replacement main waits for COMMIT makes it exit with `waiting for commit` while the old main is already fenced: the proxy stops abruptly instead of softly. The `PausedCommandHub::handle_sigterm` doc comment claimed such a signal is honoured by the new Hub's event loop. 2. A rolled-back main upgrade can leave a 0-byte pid file where none existed before. 3. The compatibility-matrix e2e reports `ok` when skipped, and its skip message is captured by libtest. ## Cause 1. `Channel::read_message_blocking_timeout` (`command/src/channel.rs`) reads with `SO_RCVTIMEO`. signal(7): such a socket read is never restarted after a handled signal, even under `SA_RESTART`, so it fails with `EINTR`. The loop retried only `WouldBlock` and returned `ChannelError::Read(Interrupted)`. 2. `util::open_pid_file` (`bin/src/util.rs`) opened with `create(true)` before PREPARED. Child-side cleanup cannot fix this: the old main SIGKILLs the child on PREPARED timeout, unexpected message, or pending SIGTERM. 3. `println!` is captured by libtest, and libtest has no skipped outcome. ## Fix 1. `ErrorKind::Interrupted => continue`. The deadline is still checked against the `Instant` captured at entry at the top of every iteration, so the wait is neither aborted nor extended. Callers: - fixed by this change: the child's COMMIT wait (`bin/src/upgrade.rs`), plus the old main's PREPARED and ACTIVATED waits (`bin/src/command/upgrade.rs`). All three run with the SA_RESTART SIGTERM handler installed. - `sozu ctl` (`bin/src/ctl/command.rs`, including the unbounded `None` wait): installs no handler, so it never sees EINTR. - `sozu top`: installs a `ctrlc` handler, but each of its reads is bounded at 5 s. 2. A missing pid file is no longer created before COMMIT. Only its parent is checked with `access(W_OK | X_OK)`, which fails on a missing parent, a non-directory, EROFS or EACCES, and `publish_pid_file` creates the file after COMMIT. An existing file is still opened before PREPARED without truncation, so the directory-at-path rollback in `upgrade_pid_file_failure_e2e` still fails before PREPARED. 3. The skip message goes to `std::io::stderr()` directly, which bypasses libtest capture. The `handle_sigterm` doc comment now describes the retry. CHANGELOG `[Unreleased]` Fixed is updated. ## Tests - `read_message_blocking_with_timeout_survives_interrupting_signals` and `read_message_blocking_with_timeout_keeps_its_deadline_under_signals` install an `SA_RESTART` `SIGUSR1` handler and `pthread_kill` the reader thread every 5 ms. Without the fix, both fail with `Read(Os { code: 4, kind: Interrupted, ... })`. With the fix, they pass in three consecutive runs. - `open_pid_file_defers_creating_a_missing_file_until_publish` fails when the old `create(true)` is restored and passes with the fix. Also added: `open_pid_file_keeps_an_existing_file_until_publish` and `open_pid_file_rejects_a_missing_parent_directory`. - Commands run, all passing: - `cargo test -p sozu -p sozu-command-lib --all-features --locked` - `cargo test -p sozu --all-features -- --ignored`, including `unwritable_pid_file_rolls_back_main_upgrade_and_keeps_serving` and `sigterm_during_prepare_aborts_upgrade_then_stops_the_old_main` - `cargo clippy --all-features --all-targets -p sozu -p sozu-command-lib -- -D warnings` - `cargo +nightly fmt --all --check` - `check_doc_citations.py --base origin/main` Refs #1846 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.
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/ACTIVATEDprotocol:CLOEXEC, and lets the unchanged old Hub continue;COMMITirreversibly fences the old Hub, so an ambiguous post-commit failure cannot execute work twice;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.
SIGTERMobserved 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
Readybits in both serialized readiness and interest, preserves them exactly, and rejects the first unknown bit0x20. This covers the Linux readiness wordWRITABLE | 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 withinvalid channel snapshot readiness bits: 0x001a, then passed 1/1 after acceptingWRITE_CLOSED.0x20in each field. RemovingWRITE_CLOSEDmakes the test fail on0x10.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.d7b5f14dbinary. 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 warningsand the equivalent FIPS matrix passed.cargo +nightly fmt --all --checkpassed..github/scripts/check_doc_citations.py --base 9561b24e61c23511326ffeb547b0b7fe51ee7055passed 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 ambientRUST_LOG=warn, which GitHub CI does not set; the test requires its configuredinfoaccess records.GitHub CI checks are pending on the rebased commit
a8bdd54b8833060576674a8c2aff0374f6e8083b.Fixes #1832