Repository navigation
Closed
Description
Checklist
- I have verified that the issue exists against the
mainbranch of Celery. - This has already been asked to the discussions forum first.
- I have read the relevant section in the
contribution guide
on reporting bugs. - I have checked the issues list
for similar or identical bug reports. - I have checked the pull requests list
for existing proposed fixes. - I have checked the commit log
to find out if the bug was already fixed in the main branch. - I have included all related issues and possible duplicate issues
in this issue (If there are none, check this box anyway). - I have tried to reproduce the issue with pytest-celery and added the reproduction script below.
Mandatory Debugging Information
- I have included the output of
celery -A proj reportin the issue.
(if you are not able to do this, then at least specify the Celery
version affected). - I have verified that the issue exists against the
mainbranch of Celery. - I have included the contents of
pip freezein the issue. - I have included all the versions of all the external dependencies required
to reproduce this bug.
Optional Debugging Information
- I have tried reproducing the issue on more than one Python version
and/or implementation. - I have tried reproducing the issue on more than one message broker and/or
result backend. - I have tried reproducing the issue on more than one version of the message
broker and/or result backend. - I have tried reproducing the issue on more than one operating system.
- I have tried reproducing the issue on more than one workers pool.
- I have tried reproducing the issue with autoscaling, retries,
ETA/Countdown & rate limits disabled. - I have tried reproducing the issue after downgrading
and/or upgrading Celery and its dependencies.
Related Issues and Possible Duplicates
Related Issues
- None
Possible Duplicates
- None
Environment & Settings
Celery version:
celery report Output:
software -> celery:5.4.0 (opalescent) kombu:5.3.7 py:3.12.3
billiard:4.2.0 py-amqp:5.2.0
platform -> system:Darwin arch:64bit
kernel version:23.5.0 imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:amqp results:redis://localhost:6379/0
broker_url: 'amqp://guest:********@localhost:5672//'
result_backend: 'redis://localhost:6379/0'
task_acks_late: True
task_reject_on_worker_lost: True
deprecated_settings: None
Steps to Reproduce
Required Dependencies
- Minimal Python Version: N/A or Unknown
- Minimal Celery Version: N/A or Unknown
- Minimal Kombu Version: N/A or Unknown
- Minimal Broker Version: N/A or Unknown
- Minimal Result Backend Version: N/A or Unknown
- Minimal OS and/or Kernel Version: N/A or Unknown
- Minimal Broker Client Version: N/A or Unknown
- Minimal Result Backend Client Version: N/A or Unknown
Python Packages
pip freeze Output:
amqp==5.2.0
billiard==4.2.0
celery @ git+https://github.com/celery/celery.git@50732166b645013626b28fc015ddd95895b6c5a3
click==8.1.7
click-didyoumean==0.3.1
click-plugins==1.1.1
click-repl==0.3.0
kombu==5.3.7
prompt_toolkit==3.0.47
python-dateutil==2.9.0.post0
redis==5.0.7
six==1.16.0
tzdata==2024.1
vine==5.1.0
wcwidth==0.2.13
Other Dependencies
Details
N/A
Minimally Reproducible Test Case
Details
app = Celery(
'hello',
broker='amqp://localhost//',
backend='redis://localhost:6379/0',
task_acks_late=True,
task_reject_on_worker_lost=True,
)
@app.task(name='ok')
def ok(*args, **kwargs):
print('ok')
return 'ok'
@app.task(name='bad')
def bad(*args, **kwargs):
print('bad')
raise Exception('bad')
@app.task(name='on_error_handler')
def on_error_handler(request, exc, traceback):
print('error detected')
@app.task(name='graph')
def graph():
print('running graph')
chord_inner = chord(
(
bad.s(),
ok.s(),
),
ok.s(),
)
chord_outer = chord(
(
bad.s(),
chord_inner,
),
ok.s(),
)
chord_outer.on_error(on_error_handler.s())
chord_outer.delay()Expected Behavior
Should call on_error_handler and print "error detected".
Actual Behavior
Never calls on_error_handler.
Importantly, note that if I replace chord_inner with bad.s() in the header, then on_error_handler is called. Meaning, on_error(...) works as intended with regular signatures in the header failing, but not nested chord signatures failing.
So, this is fine:
chord_outer = chord(
(
bad.s(),
bad.s(),
),
ok.s(),
)
chord_outer.on_error(on_error_handler.s())
But this is not:
chord_outer = chord(
(
bad.s(),
chord_inner,
),
ok.s(),
)
chord_outer.on_error(on_error_handler.s())
[2024-06-27 12:39:39,979: INFO/MainProcess] Task bad[d285c927-aa7c-4167-9732-d914c9094498] received
[2024-06-27 12:39:39,980: WARNING/ForkPoolWorker-1] bad
[2024-06-27 12:39:39,989: INFO/MainProcess] Task bad[b3e91204-905c-41e5-ae34-d398e69ce1a9] received
[2024-06-27 12:39:39,990: INFO/MainProcess] Task ok[9053fb18-f333-417c-bc7b-04c95dedfb1a] received
[2024-06-27 12:39:39,991: WARNING/ForkPoolWorker-9] bad
[2024-06-27 12:39:39,991: INFO/ForkPoolWorker-8] Task graph[a728c96b-5935-48ef-ad71-71cb6b50a58c] succeeded in 0.04279591701924801s: None
[2024-06-27 12:39:39,992: WARNING/ForkPoolWorker-2] ok
[2024-06-27 12:39:39,992: ERROR/ForkPoolWorker-1] Task bad[d285c927-aa7c-4167-9732-d914c9094498] raised unexpected: Exception('bad')
Traceback (most recent call last):
File "/Users/foo/code/test-celery/venv/lib/python3.12/site-packages/celery/app/trace.py", line 453, in trace_task
R = retval = fun(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^
File "/Users/foo/code/test-celery/venv/lib/python3.12/site-packages/celery/app/trace.py", line 736, in __protected_call__
return self.run(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/foo/code/test-celery/tasks.py", line 24, in bad
raise Exception('bad')
Exception: bad
[2024-06-27 12:39:39,998: ERROR/ForkPoolWorker-9] Task bad[b3e91204-905c-41e5-ae34-d398e69ce1a9] raised unexpected: Exception('bad')
Traceback (most recent call last):
File "/Users/foo/code/test-celery/venv/lib/python3.12/site-packages/celery/app/trace.py", line 453, in trace_task
R = retval = fun(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^
File "/Users/foo/code/test-celery/venv/lib/python3.12/site-packages/celery/app/trace.py", line 736, in __protected_call__
return self.run(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/foo/code/test-celery/tasks.py", line 24, in bad
raise Exception('bad')
Exception: bad
[2024-06-27 12:39:39,999: ERROR/ForkPoolWorker-2] Chord '85ae8187-16fe-458e-b9ea-a49690a6e825' raised: ChordError("Dependency b3e91204-905c-41e5-ae34-d398e69ce1a9 raised Exception('bad')")
Traceback (most recent call last):
File "/Users/foo/code/test-celery/venv/lib/python3.12/site-packages/celery/backends/redis.py", line 528, in on_chord_part_return
resl = [unpack(tup, decode) for tup in resl]
^^^^^^^^^^^^^^^^^^^
File "/Users/foo/code/test-celery/venv/lib/python3.12/site-packages/celery/backends/redis.py", line 434, in _unpack_chord_result
raise ChordError(f'Dependency {tid} raised {retval!r}')
celery.exceptions.ChordError: Dependency b3e91204-905c-41e5-ae34-d398e69ce1a9 raised Exception('bad')
[2024-06-27 12:39:40,000: INFO/ForkPoolWorker-2] Task ok[9053fb18-f333-417c-bc7b-04c95dedfb1a] succeeded in 0.008979458012618124s: 'ok'
Activity
JerroldJV commentedon Jul 31, 2024
I also am seeing this issue, but also if the header tasks contain chains or groups.
This is a major issue for us in our production code, as we have a long-running group of tasks that when running are acquiring an external lock, but we have no consistent way to release that lock if any of the tasks fail (which happen sometimes due to intermittent issues).
thedrow commentedon Aug 14, 2024
Is
task_allow_error_cb_on_chord_headerturned on?See docs.
naktinis commentedon Aug 14, 2024
If I understand correctly, the docs say this about the default behaviour (
task_allow_error_cb_on_chord_headerturned off):Which sounds like exactly what I need, that is on any header failure:
error_callback_sigwill be called once,However, in my example
error_callback_sigis not called, contrary to the above definition.Just to map to the example of the default behavior (with that flag off) in the documentation, I can rewrite the main part of my minimal reproducible example (included in the task description) as below.
This should call
error_callback_sigonce but, contrary to documentation, never calls it:This seems to call
error_callback_sigonce if you callchord_outer.apply_async()for the first time, and twice for any repeated call:crayola commentedon Nov 28, 2024
I am also affected on 5.5.0rc2. To be very specific, it seems to me that if at least one chord with at least one failure exists in the header of a chord, the error callback on the body of that chord will fail to run. If the failure is elsewhere, it will run.
So this works;
error_callback()is called:But the callback is not called here:
Nusnus commentedon Feb 24, 2025
Fixed in
main.@naktinis @JerroldJV @crayola you’re welcome to test it out.
Will be released soon in the next release candidate for v5.5.