Skip to content

fix(daemon): register SIGTERM handler to ensure PID file cleanup#1438

Merged
bug-ops merged 2 commits intomainfrom
daemon-pid-cleanup
Mar 9, 2026
Merged

fix(daemon): register SIGTERM handler to ensure PID file cleanup#1438
bug-ops merged 2 commits intomainfrom
daemon-pid-cleanup

Conversation

@bug-ops
Copy link
Owner

@bug-ops bug-ops commented Mar 9, 2026

Summary

  • Registers SIGTERM handler alongside the existing Ctrl-C handler using a tokio::select! block in the daemon signal task
  • Both SIGINT and SIGTERM now trigger shutdown_tx.send(true), ensuring agent.shutdown() and remove_pid_file() are always reached on clean shutdown
  • Renames shutdown_tx_ctrlc to shutdown_tx_signal to reflect the expanded scope

Closes #1414

Test plan

  • cargo +nightly fmt --check — pass
  • cargo clippy --workspace --features full -- -D warnings — pass (0 warnings)
  • cargo nextest run --config-file .github/nextest.toml --workspace --features full --lib --bins — 4869 passed, 11 skipped
  • Existing crates/zeph-core/src/daemon.rs tests cover write_pid_file/remove_pid_file roundtrip and DaemonSupervisor shutdown watch channel

…hutdown

Only ctrl_c() was registered as a signal handler, causing remove_pid_file()
to be skipped when the daemon received SIGTERM (standard `kill <pid>`).

Replace the single ctrl_c handler with a tokio::select! block covering both
SIGINT and SIGTERM. Both signals now trigger shutdown_tx.send(true), allowing
the cleanup path (agent.shutdown + remove_pid_file) to always execute.

Closes #1414
@github-actions github-actions bot added documentation Improvements or additions to documentation bug Something isn't working size/S Small PR (11-50 lines) labels Mar 9, 2026
@bug-ops bug-ops enabled auto-merge (squash) March 9, 2026 12:06
@bug-ops bug-ops merged commit 75d394e into main Mar 9, 2026
18 checks passed
@bug-ops bug-ops deleted the daemon-pid-cleanup branch March 9, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation size/S Small PR (11-50 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Daemon PID file not cleaned up on SIGTERM shutdown

1 participant