feat(server): drain in-flight solves on SIGTERM / Ctrl-C#4
Open
KeyCode17 wants to merge 1 commit into
Open
Conversation
Wire `axum::serve(...).with_graceful_shutdown(shutdown_signal())`. The signal handler resolves on the first of: - SIGINT (Ctrl-C from a TTY) - SIGTERM (sent by systemd, Kubernetes, `kill`) — Unix only; on other targets the SIGTERM branch is a pending future so SIGINT alone still wins. After either signal we log a single "draining in-flight solves" line; axum stops accepting new connections, lets the existing `/v1/solve` requests finish, and the binary exits with a clean "px-server stopped cleanly" log. Errors installing the handlers log a warning but do not abort the process — the worst case degrades to the previous "hard kill" behaviour. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
Wire
axum::serve(...).with_graceful_shutdown(shutdown_signal())so the server stops accepting new connections on the first of SIGINT or SIGTERM and lets the in-flight/v1/solverequests finish before the process exits.kill) both trigger the drain.Why
Under the previous
axum::serve(...).awaitform, sending SIGTERM (the systemd defaultKillSignal) aborted the runtime and dropped any in-flight/v1/solverequests mid-flight, which can leave the Chromium / Camoufox harvester pool in an inconsistent state (open browsers, zombie processes — exactly what MVP-AC-4 prohibits). A clean drain is also a prerequisite for the "weekly auto-soak" follow-up from ADR-0022 because the soak script can now restart the server between runs without ungraceful kills.Test plan
cargo build -p px-servercargo test -p px-server --lib— all 6 unit tests passcargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-featuresagainst the lefthook rule setpx-server/src/main.rsstays under the 200-LOC axum-best-practice rule (162 LOC)Notes for the reviewer
Dropimpls already kill child Chromium / geckodriver processes once the dispatchers are released, and a clean drain makes those Drops actually run.🤖 Generated with Claude Code