Repository navigation
Description
When a worker receives a task name it doesn't have, it stores FAILURE for that task and stops there: the errback isn't called, and the task's chain and chord stay PENDING. This happens in a rolling deploy, when a new task is called before every worker has it. It has been this way since 4.0.0 and is the same on 5.4.0 and 5.5.3. I'd pass the chord, the errbacks and the chain from the message to the failure handling, and I can send that PR.
| Main (9c2f238), the second task is | Alone, with link_error |
In a chain | In a chord header |
|---|---|---|---|
| A name the worker doesn't have | FAILURE, errback not called | Next step PENDING | Body PENDING, errback not called |
| A task that raises | FAILURE, errback called | Next step FAILURE | Body FAILURE, errback called |
Each row is 3 of 3 runs.
Cause
Consumer.on_unknown_task() builds its own request for mark_as_failure() with chord=None and errbacks=None, and without the chain (celery/worker/consumer/consumer.py:767 and :770). The message carries all three. That request is from 5c8f03b (2016, first released in 4.0.0). Before it the failure was stored with no request at all.
Checklist
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. - 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
- Chains with unregistered tasks fail to call callbacks (send_task bug) #1522, closed in 2013, was about callbacks of unregistered tasks in chains.
- Chord across multiple apps using signatures breaks on task not registered #6846, closed, was about a chord across apps that hit
NotRegistered.
Possible Duplicates
- None
Environment & Settings
Celery version: 5.7.0 (9c2f238)
celery report Output:
software -> celery:5.7.0 (collider) kombu:5.7.0 py:3.14.6
billiard:4.3.2 redis:8.1.0
platform -> system:Linux arch:64bit, ELF
kernel version:6.18.44-fc-v378 imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:redis results:redis://localhost:6379/1
broker_url: 'redis://:********@localhost:6379/0'
result_backend: 'redis://localhost:6379/1'
deprecated_settings: None
Steps to Reproduce
Required Dependencies
- Minimal Python Version: N/A or Unknown
- Minimal Celery Version: 5.4.0 tested (4.0.0 by the code)
- Minimal Kombu Version: N/A or Unknown
- Minimal Broker Version: Redis 7.4
- Minimal Result Backend Version: Redis 7.4
- 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:
billiard==4.3.2
celery @ main (9c2f238)
kombu @ main (445027e)
redis==8.1.0
Other Dependencies
Services
N/A
Minimally Reproducible Test Case
tasks.py, run.py and output
# tasks.py
import redis
from celery import Celery
app = Celery("tasks", broker="redis://localhost:6379/0",
backend="redis://localhost:6379/1")
log = redis.Redis(db=2)
@app.task
def ok(i):
return i
@app.task
def fails():
raise ValueError("boom")
@app.task
def body(results):
log.rpush("calls", "body")
@app.task
def errback(request, exc, traceback):
log.rpush("calls", "errback")# run.py
import sys
import time
from celery import chain, chord
from tasks import app, body, errback, fails, log, ok
# A task this worker doesn't have, as during a rolling deploy.
bad = fails.s() if sys.argv[1:] == ["raise"] else app.signature("tasks.added_in_the_next_release")
log.delete("calls")
alone = bad.clone().apply_async(link_error=errback.s())
in_chain = chain(bad.clone(), ok.si(2)).apply_async()
in_chord = chord([ok.s(1), bad.clone()])(body.s().on_error(errback.s()))
time.sleep(6)
print("alone:", alone.state,
"| chain:", in_chain.parent.state, "then", in_chain.state,
"| chord body:", in_chord.state,
"| errback calls:", log.lrange("calls", 0, -1).count(b"errback"))$ celery -A tasks worker -c 2 -l warning
$ python run.py
alone: FAILURE | chain: FAILURE then PENDING | chord body: PENDING | errback calls: 0
$ python run.py raise
alone: FAILURE | chain: FAILURE then FAILURE | chord body: FAILURE | errback calls: 2Expected Behavior
An unknown task fails like any other task: its errbacks are called, the rest of its chain fails, and its chord fails with a ChordError.
Actual Behavior
The task is stored as FAILURE with NotRegistered and nothing else happens. A caller that waits for the chord or the chain waits until its timeout.
Activity
Pass chord, chain, and errbacks to mark_as_failure on unknown task (#…