Repository navigation
fix(worker): store no failure for a task requeued by a time limit - #11185
Open
ChristianMurphy wants to merge 1 commit into
Open
ChristianMurphy wants to merge 1 commit into
ChristianMurphy wants to merge 1 commit into
Conversation
Problem: with acks_late on and acks_on_timeout off, a hard time limit requeues the message and the task runs again. Request.on_timeout() still stored FAILURE and called the errbacks for that run. Since 5.7.0 it also sent task_failure and task-failed and called Task.on_failure and after_return. A caller got TimeLimitExceeded for a task that then ran again and could succeed. Goal: a run whose message is requeued leaves no failure behind, as Request.on_failure() already does when it requeues. Changes: - on_timeout() skips the failure handling when the message is requeued. The "Hard time limit" log line stays. - A unit test covers the prefork order, where on_failure() runs first, and the gevent order, where only on_timeout() runs. - A smoke test runs a task that exceeds its limit on the first delivery only. - The docs for task_acks_on_timeout and the time limit note in the tasks guide describe the new behavior. Notes: the unit test that asserted the old behavior, test_hard_time_limit_requeued_by_on_failure_is_handled_by_on_timeout, is replaced by the new one. The requeue case in test_on_hard_timeout_acks_on_failure_or_timeout now expects PENDING, not FAILURE. Refs: celery#11090
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #11185 +/- ##
==========================================
+ Coverage 91.81% 91.82% +0.01%
==========================================
Files 153 153
Lines 22296 22316 +20
Branches 2794 2799 +5
==========================================
+ Hits 20471 20492 +21
+ Misses 1530 1529 -1
Partials 295 295
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
This branch has not been deployed
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.
Note: Before submitting this pull request, please review our contributing
guidelines & Anti AI spamming Guidelines. Before opening an AI based PR make sure you asked
in the discussion forum or in the related open issues first.
Description
Refs #11090. This is the requeue case that @auvipy asked me to take on in #11105. With
acks_lateon andtask_acks_on_timeoutoff, a task that hits its hard time limit is requeued and runs again, but that run was still stored as FAILURE and its errbacks ran. A caller gotTimeLimitExceededfor a task that then ran again and could succeed.Request.on_timeout()now skips its failure handling when it requeues the message, asRequest.on_failure()already does. Nothing is stored for that run, and no errback,task_failuresignal,task-failedevent,Task.on_failureorafter_returnruns. The "Hard time limit" log line and thetask-rejectedevent stay.The trade-off is a task that exceeds its limit on every run. It is requeued each time, as before, and now only the log line shows it, because no FAILURE is stored between runs. On a RabbitMQ quorum queue the message is dropped after 20 redeliveries by default, and then nothing is stored for the task. The docs say so.
This is separate from #11183, which stops the result store wait before the worker's own time limits. The two change different code paths and merge without a conflict.
The store and the errbacks on a requeue date from 5.5.0, when #9626 added the requeue. The signal, the event and the two task hooks date from 5.7.0 (#10226).
acks_on_timeoutoffget()TimeLimitExceededtask_failuresignalsThat is 3 of 3 runs on Redis 7.4 and 3 of 3 on Valkey 8.1, with the prefork pool. A task with
acks_on_timeouton behaves the same on main and here: FAILURE, one errback call, one run.Most of the diff is tests and docs: code +5, tests +83/−25, docs +23.
on_failure()and thenon_timeout(), and the gevent pool calls onlyon_timeout(). It fails on main in both.test_hard_time_limit_requeued_by_on_failure_is_handled_by_on_timeoutasserted the old behavior, so the new test replaces it. The requeue case intest_on_hard_timeout_acks_on_failure_or_timeoutnow expects PENDING, not FAILURE, for the same reason.What I ran
tox -e 3.13-unit: 5783 passed, 34 skipped, 1 xfailed.t/unit/worker/test_request.pywith main'scelery/worker/request.py: 3 fail, the new test in both orders and the changed assertion.acb1428d2) against this branch, kombu main (9cd1cef8), Python 3.13, prefork with 2 processes, a task withtime_limit=2.tox -e 3.13-smokewith the two hard time limit smoke tests: 4 passed here. On main the new one fails withTimeLimitExceeded, on both brokers.