Repository navigation
Description
Checklist
- 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).
software -> celery:4.0.2 (latentcall) kombu:4.0.2 py:2.7.12
billiard:3.5.0.2 redis:2.10.5
platform -> system:Linux arch:64bit, ELF imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:redis results:redis://localhost:6379/
BROKER_TRANSPORT_OPTIONS: {
'fanout_patterns': True, 'fanout_prefix': True}
CELERY_TASK_COMPRESSION: 'gzip'
CELERY_RESULT_SERIALIZER: 'json'
CELERY_BROKER_URL: u'redis://localhost:6379//'
DEBUG_PROPAGATE_EXCEPTIONS: False
CELERY_ACCEPT_CONTENT: ['application/json']
CELERY_TIMEZONE: 'UTC'
CELERY_MESSAGE_COMPRESSION: 'gzip'
USE_TZ: True
CELERY_RESULT_BACKEND: u'redis://localhost:6379/'
CELERY_FLOWER_URL: 'http://localhost:5556'
- I have verified that the issue exists against the
masterbranch of Celery.
I do not have the time resource to test different versions of celery while at work. This project is at work and I have other things to do while worrying about callbacks not being queued/called. If I do get time to test on master, I will.
Steps to reproduce
Run about 100 task header of a chord, with a callback. The chord is started through .delay().
Usage is similar to what the docs have:
chord((import_contact.s(c) for c in contacts), notify_complete.si(import_id)).apply_async(). In my case, I do not use an immutable signature, and i pass many kwargs into the callback/body.
Expected behavior
I expect that once my header has completed, that the callback will run.
Actual behavior
Depending on how long the header tasks run for, the callback is not called. I'm still trying to figure out if it is a time or memory or other sort of issue. But, I wanted to get the issue created while I'm looking through it further.
It's also possible that it doesn't have to do with how long it takes at all. I'll try updating further.
Activity
[-]Chord callback not always called when header tasks complete.[/-][+]Chord callback/body not always called when header tasks complete.[/+]auvipy commentedon Dec 19, 2017
If you could verify this again on top of latest master plz ping me to reopen
jheld commentedon Nov 20, 2018
My new leading hypothesis is that this is related to my project's use of
result_expires. We used to have this set at 60 seconds, and now we have it at 10 seconds.Tonight I decided to revisit this (we're using celery
4.2.0). There are a few workflows that would benefit us from having this work all of the time; we've been hesitant to utilize thechordbecause we were having issues with it running the body all the time.Now, if we have, say, 1 task, and we have a header of 2 of them being called (say
addeach), and then let the body also be anadd, if we lower the result expire to 1 second, and also include atime.sleep(2)in theaddimplementation, I've never seen thebodytask run.Playing with the result expires and the "task time" (fake long task with a time.sleep) seems like the culprit.
There is documentation around result expires, however, if this is the issue for the
redisbackend, then the docs should warn against setting a low task expire results time, in the case of achord.At this point, I'm fairly confident that this is the bug.
Below is the section of code which introduces the notion of the adjusted completed task count.
When I add more logs around the readycount vs total (chord_size), and when I see the issue rear its head, its because it never reaches the
total. You'll note theself.expiresAnd
self.expiresgets its value from:So, I wonder, should the tkey and jkey be honoring the result expires (or at least, the one set in the config, as opposed to the
daydefault)? Is there any harm in having it be no less than 1 day, or perhaps, making it its own setting?Or, is this really just a documentation update to help users?
jheld commentedon Nov 20, 2018
@auvipy please see above.
jheld commentedon Nov 20, 2018
Would it be possible to have a per-task (possibly even on
chord, too) result expires setting? My team would be very interested in that usage.We don't care about most of the results of our task runs (in practice), but we don't necessarily wish to always use
ignore_result, especially if we need the task result around at least briefly but we forget about the global setting.[-]Chord callback/body not always called when header tasks complete.[/-][+]Chord body will not be called if result expires is too low[/+][-]Chord body will not be called if result expires is too low[/-][+]Chord body will not be called if result_expires is too low[/+]auvipy commentedon Feb 17, 2021
when you have time can you revisit the current codes & share your current consensus on that? we can dig further based on your finding. I know it so old & sorry for taking so long to reply.
ChristianMurphy commentedon Oct 6, 2026
This still reproduces on 5.6.3 with the Redis backend. A chord of three tasks that each sleep 3 seconds, on a single worker with
result_expires=1, never runs its body. Withresult_expires=60it runs.The cause looks like
on_chord_part_return: each finished header task resets the chord's.j,.tand.skeys to expire afterresult_expires. If the gap between two header tasks finishing is longer than that, the keys are gone and the body never fires.mainhas the same code.One narrow fix would be to keep those keys until the body is sent. They're already deleted at that point, so no expiry is needed while the chord is open. Another option is a separate expiry for chord keys. Would either be welcome? Happy to send a PR with tests.
auvipy commentedon Oct 8, 2026
can you reproduce with v5.7.0b1?
ChristianMurphy commentedon Oct 8, 2026
Yes, it still reproduces on 5.7.0b1 with the same chord setup. I can send a PR.
ChristianMurphy commentedon Oct 9, 2026
The same chord also fails on the memcached backend with 5.7.0b1, through a different path. The group record saved at chord start is never refreshed. Once it expires, each header task fails with
ValueError(<group id>)inon_chord_part_return, and the body never runs. Withresult_expires=60the body runs, and withresult_expires=1it doesn't. #10827 only covers Redis. I can look at memcached separately if that's useful.auvipy commentedon Oct 9, 2026
sure thing.