Repository navigation
fix: send the task failure in hard timeout - #10226
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #10226 +/- ##
=======================================
Coverage 88.24% 88.25%
=======================================
Files 153 153
Lines 19591 19606 +15
Branches 2252 2254 +2
=======================================
+ Hits 17289 17303 +14
Misses 2004 2004
- Partials 298 299 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Contributor
There was a problem hiding this comment.
Pull request overview
Ensures hard time limits trigger the same failure side-effects as other task failures (task hooks, task_failure signal, and monitoring events), and documents the updated semantics.
Changes:
- Update
Request.on_timeout(soft=False)to invokeTask.on_failure,Task.after_return(when overridden), emitsignals.task_failure, and send thetask-failedevent after marking the task as failed. - Add unit tests covering hard-timeout failure hooks, signal emission, event emission, and
after_return. - Document hard vs soft time limit semantics and update the custom request guidance.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
celery/worker/request.py |
Adds failure hook/signal/event emission to the hard-timeout path. |
t/unit/worker/test_request.py |
Adds regression tests asserting the new hard-timeout failure side-effects. |
docs/userguide/tasks.rst |
Documents the updated hard-timeout behavior and adjusts related guidance. |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
auvipy
approved these changes
Mar 31, 2026
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
Hard time limits now invoke
task.on_failure(),task.after_return(), and thetask_failuresignal in the parentworker process, matching the behavior of soft time limits.
Previously, when a hard time limit fired, only
backend.mark_as_failure()was called.task.on_failure(),task.after_return(), signals.task_failure, and the task-failed monitoring event were silently skipped, makingit impossible for users to rely on standard failure hooks for cleanup or observability when a hard timeout
occurred.
Closes #10194
Root Cause
Request.on_timeout(soft=False)incelery/worker/request.pyonly calledmark_as_failure()and handled ack/reject. The failure side-effects that the normal task tracer triggers were never wired up for the hard-timeout path.Note: errbacks were already triggered via
mark_as_failure(call_errbacks=True)before this fix.Changes
celery/worker/request.py
After mark_as_failure(), the hard-timeout path now:
self.task.on_failure(exc, self.id, self.args, self.kwargs, einfo).self.task.after_return(states.FAILURE, ...)if the task overrides it (guarded bytask_has_custom, consistent with the tracer).get_pickled_exception(consistent with Request.on_failure).All additions are guarded by the existing if not state.should_terminate block so cold-shutdown behavior is unchanged.
docs/userguide/tasks.rst