Fix airflow celery stop crashing on stale PID file - #72817
Merged
dheerajturaga merged 2 commits intoSep 15, 2026
Merged
Conversation
Eason09053360
requested review from
dheerajturaga and
hussein-awala
as code owners
September 9, 2026 15:27
rjgoyln
reviewed
Sep 9, 2026
Contributor
There was a problem hiding this comment.
LGTM overall! I verified the new parametrization against the unpatched stop_worker: both added cases fail with psutil.NoSuchProcess without the fix and pass with it. The full file also passes (30 passed, 2 skipped). remove_existing_pidfile already handles ENOENT, so the stale-PID path correctly remains idempotent.
Two non-blocking notes below, both on the new test.
Just my thoughts — feel free to resolve if you think otherwise.
Drafted-by: Claude Code (Opus 5); reviewed by @rjgoyln before posting
When a Celery worker dies without cleaning up its PID file (SIGKILL, OOM, host reboot), `airflow celery stop` reads the dead PID, fails with an uncaught psutil.NoSuchProcess traceback, and never reaches the PID-file removal. Every subsequent `stop` fails the same way until the operator deletes the file by hand. The worker start path already treats NoSuchProcess as "stale PID file, clean it up" in check_if_pidfile_process_is_running; the stop path is the only reader that did not. Only NoSuchProcess is handled on purpose: AccessDenied means a live process the caller cannot signal, and its PID file must not be removed.
Co-authored-by: rjgoyln <151457491+rjgoyln@users.noreply.github.com>
eladkal
force-pushed
the
fix-celery-stop-stale-pid-file
branch
from
September 15, 2026 14:14
1b67d8f to
30b7128
Compare
dheerajturaga
approved these changes
Sep 15, 2026
dheerajturaga
left a comment
Member
There was a problem hiding this comment.
Looks good overall. Minor, non-blocking suggestion: assert the new stale-PID warning with structured caplog for both NoSuchProcess cases.
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.
When a Celery worker dies without cleaning up its PID file (SIGKILL, OOM, host reboot),
airflow celery stopreads the dead PID, crashes with an uncaughtpsutil.NoSuchProcesstraceback, and never reaches the PID-file removal at the end ofstop_worker. Every subsequentstopfails the same way until the operator deletes the file by hand.After this change the command logs a warning, removes the stale file and exits 0, which matches the existing behaviour when no PID file exists at all (
stopis idempotent).The worker start path already treats
NoSuchProcessas "stale PID file, clean it up" incheck_if_pidfile_process_is_running; the stop path was the only reader that did not.Only
NoSuchProcessis handled on purpose.psutil.AccessDeniedmeans a live process the caller cannot signal (for example a worker started as root andstoprun as another user); removing its PID file would be wrong, so that case still surfaces as an error.Tests
test_if_right_pid_is_readis parametrized over three cases: worker running, PID file stale, and worker exiting betweenpsutil.Process()andterminate(). The last two fail without the fix.airflow edge stophas the same shape of bug; it lives in a different provider and will be addressed separately.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Fable 5.1) following the guidelines