Repository navigation
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. - 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
- KeyValueStoreBackend: assumes chord's group result exists #1094 added the "GroupResult no longer exists" error. A 2013 comment there describes this case.
- Fix#10997 - redis chord claim cleanup ownership #10998 (for Redis backend: chord body can be dispatched twice when a duplicate header task finishes during callback dispatch #10997) gave the Redis backend a "done" marker for duplicate headers. The incr backends have none.
Possible Duplicates
- None
Environment & Settings
Celery version: 5.7.0 (main at 768e476, kombu main at 7dca15a).
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
broker_url: 'redis://:********@localhost:6379/10'
result_backend: 'cache+memcached://127.0.0.1:11211/'
task_acks_late: True
worker_prefetch_multiplier: 1
broker_transport_options:
'unacked_restore_interval': 1,
'unacked_restore_throttle': 1,
'visibility_timeout': 2}
Steps to Reproduce
Required Dependencies
Minimal versions
- Minimal Result Backend Client Version: pymemcache 4.0.0
- Others: N/A or Unknown
Python Packages
pip freeze Output:
amqp==5.4.2
billiard==4.3.2
celery @ main (768e476)
kombu @ main (7dca15a)
pymemcache==4.0.0
redis==8.1.0
vine==5.1.0
Other Dependencies
Redis 7.4 as the broker, memcached 1.6.45 for results.
Minimally Reproducible Test Case
tasks.py, run.py and output
# tasks.py
import time
from celery import Celery
app = Celery("tasks", broker="redis://localhost:6379/10", backend="cache+memcached://127.0.0.1:11211/")
app.conf.update(
task_acks_late=True,
worker_prefetch_multiplier=1,
# Redeliver a task still running after 2 s (default 1 h), checking every second.
broker_transport_options={"visibility_timeout": 2, "unacked_restore_interval": 1,
"unacked_restore_throttle": 1},
)
@app.task(bind=True)
def header(self, i):
# Only the first delivery outlasts the visibility timeout.
redelivered = (self.request.delivery_info or {}).get("redelivered")
time.sleep(0.2 if redelivered else 4)
return i
@app.task
def body(results):
print(f"body ran with {results}")
return sum(results)
@app.task
def on_chord_error(request, exc, traceback):
print(f"errback called for {request.id}: {exc!r}")# run.py
import time
from celery import chord
from tasks import body, header, on_chord_error
results = [chord([header.s(0), header.s(1)])(body.s().on_error(on_chord_error.s())) for _ in range(5)]
time.sleep(90)
print("states:", [r.state for r in results])$ celery -A tasks worker -P prefork -c 2 -l info &
$ python run.py
states: ['SUCCESS', 'SUCCESS', 'SUCCESS', 'SUCCESS', 'SUCCESS']
worker log: "body ran" 5 times, "errback called" 10 times, e.g.
errback called for 1e939fde-...: ChordError('GroupResult a66bb22a-... no longer exists')Expected Behavior
The body runs once per chord, and the errback doesn't run, because no task failed. The chord docs say errbacks run "just once if any task in the chord header or body fails".
Actual Behavior
With the memcached result backend, the errback runs once for every header task that the broker delivers again after the chord finished, although the body ran and every task succeeded. The worker also logs ERROR ... Chord callback '<group id>' raised: ValueError('<group id>') each time.
| 5 chords of 2 headers each | body runs | errback runs |
|---|---|---|
| memcached result backend | 5 | 10 |
| Redis result backend, same setup | 5 | 0 |
In longer runs: memcached 20 of 20 chords, Redis backend 0 of 20, database backend 0 of 10. Without task_acks_late, prefetched headers that waited past the visibility timeout also ran twice (10 of 20 chords). When the errback ran first, a client polling the body saw FAILURE (ChordError) before SUCCESS in 3 of 4 chords.
The memcached backend counts chord parts with incr (BaseKeyValueStoreBackend.on_chord_part_return). The last part deletes the group result after it sends the body. A header that runs again later can't restore the group, so on_chord_part_return calls chord_error_from_stack with "GroupResult no longer exists", which calls the body's errbacks. DynamoDB uses the same code. I didn't test it.
Once someone confirms it, I'm happy to follow up with a PR.
Activity
ChristianMurphy commentedon Nov 8, 2026
The same redelivered header causes a second problem on these backends, before the chord finishes: it is counted twice. #10910 reported that for the Redis backend, and #10919 fixed it there only. memcached, and by the same code DynamoDB and GCS, still count it twice. When a header task runs longer than
visibility_timeout, the Redis broker delivers it again and both runs callincr(celery/backends/base.py:1456;gcs.py:265for GCS). The count hits the chord size while another header is still running. The join then waitsresult_chord_join_timeoutand fails the chord with aTimeoutError, although no header failed. The body never runs.visibility_timeout=2,acks_late, preforkvisibility_timeout=60(no redelivery)The short timeout stands for the default of one hour with headers of 1.5 and 6 hours; the join timeout stays at its default of 3 seconds, so with real durations the long header is even further from done. Celery main at 768e476, kombu 5.7.0.
Counting each header task once, by task id and header index as #10919 does, would fix this here too. memcached's
addon a key per header part does that in one call. Should a maintainer want it, I can send that as a PR with a test that fails on main.Script and output
The worker log for each chord:
What each run did
In every failed chord the short header started twice, about 3 seconds apart (the restore pass after
visibility_timeout), and both runs ended before the long header did. The second end made the counter equal the chord size, and the chord error came 3 seconds later, while the long header was still running. In the second memcached run and in the controls each chord had a fresh queue and worker, because the broker keeps redelivering headers that outlive the timeout and those copies would otherwise delay the next chord; the first run waited for each chord's copies to finish instead.auvipy commentedon Nov 8, 2026
is it new bug or old?
ChristianMurphy commentedon Nov 8, 2026
Old. Both problems show up on every release I tried, back to 5.3.6. The errback branch dates from 2013 (for #1094), and #10919 fixed the double count for Redis only.
Same scripts on each version, with kombu main under each so only Celery changes, memcached 1.6, prefork,
acks_late,visibility_timeout=2:1a48583)Main hits the errback more often. On the older releases, the other 6 late copies found the group result still there and only logged
Chord counter incremented too many times. The chord code inbase.pyis the same. The memcached client is not: 5.7 moved topymemcache, and the older releases run here withpython-memcached. I haven't pinned down why that changes the count.Happy to send a PR for either part, with tests that fail on main.
auvipy commentedon Nov 9, 2026
OK