Repository navigation
Skip Granian's unexpected-exit log for clean worker exits - #7538
Conversation
A group SIGTERM or SIGINT reaches the worker and the supervisor at once. The worker shuts down through its own signal handler and exits 0, while the supervisor, blocked in the watchfiles reloader, has not run its handler yet, so interrupt_by_parent is not set when the watcher thread joins the worker. Granian then logs "Unexpected exit from worker-1". A worker process only exits 0 from that handler, so treat exit code 0 as a requested stop and skip granian's watcher. Crashes keep a non-zero code and are still reported. Thread workers of free-threaded builds have no exit code and keep granian's handling. The socket is still released when no worker is left serving. Fixes reflex-dev#7266
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d22129cd2b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Merging this PR will not alter performance
|
A worker exiting 0 is no longer enough on its own to skip Granian's report. The watcher now also waits up to a second for the supervisor's interrupt event, which its SIGINT/SIGTERM handler sets as soon as the watchfiles reloader hands control back. A worker that exits 0 without any signal, such as an app module raising SystemExit(0) on import, keeps the "Unexpected exit" diagnostic after that grace period. The regression test now also covers the clean exit releasing the socket when no worker is left, and the unsignalled zero exit reaching Granian's watcher. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01KUjvFSWE66oQT5YUbSLTQZ
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
The watcher released the shared socket only after the grace wait, so a worker exiting 0 with no signal left the port bound with nobody serving for up to a second. Releasing first keeps the port closed from the moment the worker is gone. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01KUjvFSWE66oQT5YUbSLTQZ
Fixes #7266. Alternative to #7457.
Problem
A group SIGTERM (or SIGINT) of a dev
reflex runreaches the Granian worker and the supervisor at the same time. The worker runs its own signal handler and exits 0. The supervisor is blocked in the watchfiles reloader, so its handler has not run yet andinterrupt_by_parentis not set when the per-worker watcher thread joins the worker. Granian then logs[ERROR] Unexpected exit from worker-1.#7457 checks
exitcode == -SIGTERM and interrupt_signal. In a real shutdown the worker exits0and the flag is usually unset, so that check never matches.Fix
A worker process exits 0 only from its own SIGINT/SIGTERM handler. The watcher now treats exit code 0 as a requested stop and skips Granian's watcher. Crashes keep a non-zero or negative exit code and are still reported. Thread workers (free-threaded builds) have no exit code and keep Granian's handling. The socket is still released when no worker is left serving. Granian's watcher only logs in this case, because Reflex sets
reload_ignore_worker_failure=True.Validation
Full
reflex run(frontend + backend), blank template, Python 3.11.15, Granian 2.8.3, Linux, group SIGTERM after the app is ready:Worker SIGKILLed, then the app stopped: the crash is logged once, and the shutdown adds no error.
One unit test checks that a worker exiting 0 skips Granian's report and a SIGKILLed worker still reaches it. It fails on main.