Repository navigation
Keep a cancelled task unacked when the child reports SystemExit - #10667
Conversation
Cold shutdown cancels the running request by sending SIGTERM to the child, whose Billiard signal handler raises SystemExit. Up to Billiard 4.3.0rc1 that killed the child and the job came back as Terminated, which on_failure leaves unacked so the broker redelivers it. Since celery/billiard#452 the worker loop catches BaseException, so the same SystemExit is marshaled back as an ordinary task failure and the acks_late branch acknowledges it: the task is dropped instead of requeued, and the visibility-timeout smoke tests wait forever for "Restoring 1 unacknowledged message(s)". Treat a SystemExit or KeyboardInterrupt result the same way as Terminated when the request was cancelled or revoked by the worker itself. A task that exits on its own is still a failure.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #10667 +/- ##
=======================================
Coverage 89.12% 89.13%
=======================================
Files 153 153
Lines 20257 20277 +20
Branches 2395 2401 +6
=======================================
+ Hits 18055 18074 +19
Misses 1898 1898
- Partials 304 305 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
auvipy
left a comment
There was a problem hiding this comment.
test task smoke tests are failing here
Looking into it now! |
|
merged the other integration test upgrade and also merged billiard 4.3 to main branch to find out all compatibility issues. only in dev billiard 4.3rc1 remains, which we can change after this task tests are working |
With Billiard >= 4.3.0 a task calling sys.exit() no longer kills the child before the result is reported: the SystemExit comes back as a failure result and the child exits right after. on_failure then tried to store the SystemExit, which the JSON serializer rejects, so no result was ever written and callers waited forever. The termination smoke tests ran into their job timeout on exactly that. Report it as WorkerLostError, as before: the process is gone either way, and a task cannot fail with SystemExit.
|
@auvipy The A task calling It didn't show up on I pushed a second commit that reports this as The remaining red check is |
|
yes I already opened a pr to change that wait a min |
Follow-up to the investigation in #10659.
With Billiard 4.3.0 the
test_reset_visibility_timeoutsmoke tests fail: afterworker: Cold shutdown (MainProcess)the worker never logsRestoring 1 unacknowledged message(s). The worker isn't stuck. It exits normally, and the task that was still running has been acknowledged and dropped instead of being requeued.Cold shutdown cancels the active request by sending
SIGTERMto the child running it, and Billiard's signal handler in the child raisesSystemExit. Up to Billiard 4.3.0rc1 that killed the child, the job came back asTerminated, andRequest.on_failurereturned early for it, so the message stayed unacked and kombu restored it on close. Since celery/billiard#452 the worker loop catchesBaseException, so the sameSystemExitis marshaled back as an ordinary task failure.on_failurethen takes theacks_latebranch,acks_on_failureis on by default, and the message gets acked. Bisecting Billiard between rc1 and 4.3.0 lands on that commit.This change treats a
SystemExit/KeyboardInterruptresult likeTerminatedwhen the request was cancelled or revoked by the worker itself. A task that exits on its own is still a failure and goes through the usual path.Checked with Billiard 4.3.0 pinned: the five failing
test_reset_visibility_timeoutcases pass, the fullt/smoke/tests/test_worker.pypasses, andt/unit/workeris unchanged apart from the three new tests. Also reproduced and re-checked on macOS with a plain prefork worker against Redis, where the in-flight message now comes back to the queue after a cold shutdown.Fixes the smoke failures blocking #10659.