Skip to content

fix(upgrade): roll back on a dangling pid-file symlink, line-clean matrix skip - #1854

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/pid-file-late-failures
Oct 4, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/pid-file-late-failures

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

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

Problem

  1. A pid path that is a dangling symlink into a missing directory passes the pre-PREPARED check, the main upgrade commits, and the post-COMMIT O_CREAT fails with ENOENT and is only logged. Before fix(command): retry interrupted blocking reads during main upgrade #1848 this case rolled back.
  2. The compatibility-matrix skip message is garbled in libtest output, e.g. test legacy_sender_survives_option3_candidate_refusal ... skipping option3-to-legacyok: set SOZU_MATRIX... (6 garbled lines in 200 parallel runs).

Cause

  1. util::open_pid_file (bin/src/util.rs) opens without create (ENOENT through the dangling link), then checks access(W_OK|X_OK) on the parent of the configured path. O_CREAT in util::publish_pid_file follows the link and creates its final target, whose parent may not exist.
  2. writeln! on unbuffered stderr issues one write(2) per format piece; libtest's progress writes and the parallel case land between them.

Fix

  1. In the NotFound branch, follow the symlink chain (symlink_metadata + read_link, relative targets resolved against the link's directory, bounded at 40 like MAXSYMLINKS, ELOOP past it) and check the final target's parent. Still creates nothing, so fix(command): retry interrupted blocking reads during main upgrade #1848's no-empty-pid-file guarantee holds.
  2. Format the message first and write it with one write_all on locked stderr, framed by \n before and after. Whether the case runs is unchanged.

Contract

Every failure that is deterministic and detectable without creating a file must fail before PREPARED (directory at path, missing parent, EROFS/EACCES, and now a dangling symlink into a missing directory). Failures detectable only by creating a file (ENOSPC, inode/disk quota, an LSM denial of the create) remain an accepted residual risk: they surface after COMMIT, are logged, and the new main keeps running (systemd still receives MAINPID=). Documented on open_pid_file, in doc/upgrade_e2e_tests.md and in the CHANGELOG.

Tests

  • New open_pid_file_rejects_a_dangling_symlink_into_a_missing_directory (red before the fix, green after) and open_pid_file_follows_a_dangling_relative_symlink_to_its_target (a creatable link target stays accepted, nothing created until publish).
  • New process test dangling_pid_file_symlink_rolls_back_main_upgrade_and_keeps_serving in upgrade_pid_file_failure_e2e (shares the existing harness via assert_upgrade_rolls_back). Red before the fix: a main upgrade that cannot write its pid file must fail; status=ExitStatus(unix_wait_status(0)), stdout="... Success: Upgrade successful ...". CI already runs the whole file with --test upgrade_pid_file_failure_e2e -- --ignored.
  • Matrix output: 200 parallel runs before: 6 garbled lines; after: 0 (every skip line intact, on its own line).

Validation (--no-default-features --features crypto-ring,opentelemetry,splice,simd): cargo test -p sozu -p sozu-command-lib, cargo test -p sozu -- --ignored --test-threads=1 (all process tests pass), cargo clippy -p sozu -p sozu-command-lib --all-targets -- -D warnings, cargo +nightly fmt --all --check, check_doc_citations.py --base origin/main.

…trix skip

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]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 59316f5 into main Oct 4, 2026
29 checks passed
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