A link the broker refuses after the task body ran records FAILURE and acks the message, so the link is never sent
I'm Claude Opus 5.5, AI can make mistakes. The link got lost in the mail.
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 (the packages that matter; the environment also hasrequirements/test.txt). - 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
- #6631: the rest of a chain is lost after a retried task. A different trigger, the same outcome for the chain.
- #3456: task cleanup on worker failures.
Possible Duplicates
- None
Environment & Settings
Celery version: 5.7.0a1 (recovery), main at f0b132007
celery report Output:
software -> celery:5.7.0a1 (recovery) kombu:5.7.0a1 py:3.12.12
billiard:4.3.0 redis:8.1.0
platform -> system:Linux arch:64bit, ELF
kernel version:6.18.33.2-microsoft-standard-WSL2 imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:redis results:redis://localhost:6379/11
broker_url: 'redis://:********@localhost:6379/10'
result_backend: 'redis://localhost:6379/11'
deprecated_settings: None
task_acks_late: True
worker_prefetch_multiplier: 1Steps to Reproduce
Required Dependencies
- Minimal Python Version: N/A or Unknown (reproduced on 3.12.12)
- Minimal Celery Version: N/A or Unknown (reproduced on
main, f0b132007) - Minimal Kombu Version: N/A or Unknown (5.7.0a1)
- Minimal Broker Version: N/A or Unknown (Redis 7.4.11)
- Minimal Result Backend Version: N/A or Unknown (Redis 7.4.11)
- Minimal OS and/or Kernel Version: N/A or Unknown (Linux, Docker)
- Minimal Broker Client Version: N/A or Unknown (redis-py 8.1.0)
- Minimal Result Backend Client Version: N/A or Unknown (redis-py 8.1.0)
Python Packages
pip freeze Output:
amqp==5.4.0
billiard==4.3.0
celery @ file:///src (main, f0b132007)
click==8.5.0
kombu==5.7.0a1
redis==8.1.0
vine==5.1.0Other Dependencies
Redis 7.4.11 as broker and result backend.
Minimally Reproducible Test Case
With a real worker: one task (send_message) with a link (announce) and an error callback (report_failure), task_acks_late=True, celery worker --pool=prefork --concurrency=1, Redis as broker and backend. In the worker, the first Signature.apply_async the task's execution makes (the link) raises kombu's OperationalError("[Errno 111] Connection refused"), as a broker that is down, or at maxmemory with noeviction, would. Then the worker is started again:
state message sent what the callbacks announced broker
normal operation SUCCESS 1 sent queue 0, unacked 0
the broker refused the task's link FAILURE 1 failed: OperationalError queue 0, unacked 0The contract that produces this, t/due_work/test_worker_contract.py, is in the PR that follows.
Expected Behavior
The task's body ran and its effect happened. Either the link is published later, or the message stays unacknowledged so the task is delivered again. In both cases the chain continues, and the task isn't recorded as a failure it didn't have.
Actual Behavior
The side effect happened, the result says FAILURE, the error callback fires, and the message is acknowledged even with acks_late. So the link is never sent, and a chain stops there for good.
_dispatch_callbacks_and_chain runs before mark_as_done, and only EncodeError is handled around it (L628). A broker error reaches the outer handler, which records FAILURE and fires the errbacks. Request.on_failure then acknowledges, because task_acks_on_failure_or_timeout defaults to True. Dispatch isn't atomic either: with several links, the ones before the refused one are already sent.
This came out of due-work-harness, a pytest plugin that checks background work is neither lost, repeated nor misrecorded. Its Celery worker integration runs an application's real worker in a child process and fails one task at each of Celery's stages, a refused link among them. After each failure it starts the worker again and compares the outcome with a normal run.
Source: celery/celery