Skip to content

fix(command): retry interrupted blocking reads during main upgrade - #1848

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/upgrade-commit-wait-eintr
Oct 4, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/upgrade-commit-wait-eintr

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

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

`Channel::read_message_blocking_timeout` reads with `SO_RCVTIMEO`, which
Linux never restarts after a handled signal even under `SA_RESTART`
(signal(7)), and it retried only `WouldBlock`. A whole-cgroup SIGTERM
reaching a replacement main waiting for COMMIT made it exit "waiting for
commit" while the old main was already fenced, stopping the proxy
abruptly. Retry `Interrupted` against the unchanged deadline.

`open_pid_file` created a missing pid file before PREPARED, so a
rolled-back upgrade left an empty pid file behind. Only check the parent
directory's access for a missing file and create it at publish, after
COMMIT.

Make the compatibility-matrix skip visible without `--nocapture`.

Refs #1846

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit c0edfa8 into main Oct 4, 2026
28 checks passed
FlorentinDUBOIS added a commit that referenced this pull request Oct 4, 2026
…trix skip (#1854)

Follow-up to #1848 (merged as c0edfa8).

`util::open_pid_file` checked a missing pid file through the parent of
the configured path, but `O_CREAT` in `util::publish_pid_file` follows a
dangling symlink and creates its final target. A link into a missing
directory passed the pre-PREPARED check, the upgrade committed, and the
post-COMMIT create failed with ENOENT and was only logged. The check now
follows the link chain (bounded at MAXSYMLINKS) and tests the final
target's parent, still creating nothing. Failures that cannot be
detected without creating a file (ENOSPC, quota, an LSM denial) stay
logged after COMMIT; the residual risk is documented on `open_pid_file`.

The compatibility-matrix skip message was written with an unbuffered
`writeln!`, one write(2) per format piece, which libtest's progress
output and the parallel case interleaved with. It is now formatted first
and written with a single `write_all`, framed by newlines.

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.

1 participant