You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Celery[redis] bunch of TID.reply.celery.pidbox objects taking a lot of memory #6089
Since there is no guidance/advise request I had to file a bug report, and I apologise for that in advance. Recently we have started having memory issues with our Redis (ElastiCache) server. Using RedisInsight i found that we have hundreds of list objects that look like 70e68057-de21-3ed6-9798-26cd42ad8456.reply.celery.pidbox that take between 50M and 150M of RAM and have TTL = -1 (in other words they do not expire!).
Question is how to prevent this from happening? Is it a bug? Is there a way to maintain these keys (periodically cleanup somehow)? Any constructive advise is welcome!
Erm... my code does not make those keys - it is Celery that does that. I am guessing they are related to some of the Chords that we run every day. Why do they have TTL = -1? Our code does not touch the Celery broker (ElastiCache instance).
I was trying to suggest that as it's being used in the production of your system, it would be wise to profile the Leakey source of celery :)
Reacted by Beau Mitchell, david-merge, Brendan Goggin, mmohamed, Roger Gonzalez, Navid Khan, goofy, Isabelle COWAN-BERGMAN, Karthik Natarajan, flav-ocrolus and 12 more
Well, this is not a regular "memory leak" - Celery creates enormous objects in Redis with TTL=-1 and if it fails to delete them for whatever reason, we have trouble...
Reacted by Beau Mitchell, Banst, Torbjorn Loken, Roger Gonzalez, Navid Khan, Isabelle COWAN-BERGMAN, Karthik Natarajan, Aivars Kalvāns, Rishabh, flav-ocrolus and 10 more
Did you read what I wrote above? :) - It is not a regular memory leak!
Celery leaves large objects in Redis with TTL=-1 and eventually Redis runs out of memory over time! We found this "the hard way" few days ago, and wrote a maintenance script that runs every week to cleanup...
I humbly believe setting TTL=-1 for those keys is a bug.
Anything related to the result expires setting? Perhaps you made the setting None so all the tasks for that worker keep their results in the backend (until TTL or eviction).
Can you provide more info?
Reacted by Asif Saif Uddin {"Auvi":"অভি"} and Roger Gonzalez
No, we do not use the result_expires setting. It should be at its default (1 day if I remember). I checked anyway with inspect conf and there was no result_expires in the output.
Did you read what I wrote above? :) - It is not a regular memory leak!
Celery leaves large objects in Redis with TTL=-1 and eventually Redis runs out of memory over time! We found this "the hard way" few days ago, and wrote a maintenance script that runs every week to cleanup...
I humbly believe setting TTL=-1 for those keys is a bug.
sorry for not being meaningfully helpful! do you have the bandwidth to come up with a workable solution to the problem? after you come with a PR we could share our effort with you.
We are hitting this issue as well. I've been trying to debug it but I wasn't able to understand the root cause yet. I'm trying to plot some of the data I have access to.
This keys are never cleanup and we are manually deleting them once in a while --each week more frequently, tho.
Not sure if related or not, but it seems our Redis gets OOM when we receive a bunch of tasks at the same time:
We are using:
celery==5.2.7
kombu==5.2.4
Is there any other important info I should be provide to help. I'm happy to keep debugging this, but I'd probably need more directions here. Note that we are only noticing this in production.
Edit: after 1h it went from 283Mb to 726Mb of pidbox keys.
Hey, I'm willing to attempt to fix that and would appreciate any help on getting the root cause clarified.
As far as I understood there are 2 TTLs in place on the Queue:
expires - controls expiration of the whole channel (redis key)
message_ttl - controls TTL of the individual messages inside the redis queue.
and it seems like to fix the issue discussed here it would be sufficient to cover only channel expiration case for redis within kombu. however, to keep the feature complete it might be beneficial to implement message_ttl support as well.
If my understanding is correct the celery/kombu#1431 should cover both expires and message_ttl so moving the discussion in that issue. Would appreciate any confirmation that my conclusions make any sense.
We're still seeing this in production. I noticed celery/kombu#2251 was merged but it doesn't appear to have resolved the issue for us. Is anyone else still experiencing this?
Activity
dejlek commentedon May 13, 2020
Erm... my code does not make those keys - it is Celery that does that. I am guessing they are related to some of the Chords that we run every day. Why do they have TTL = -1? Our code does not touch the Celery broker (ElastiCache instance).
auvipy commentedon May 13, 2020
I was trying to suggest that as it's being used in the production of your system, it would be wise to profile the Leakey source of celery :)
dejlek commentedon May 13, 2020
Well, this is not a regular "memory leak" - Celery creates enormous objects in Redis with TTL=-1 and if it fails to delete them for whatever reason, we have trouble...
auvipy commentedon May 17, 2020
https://stackoverflow.com/questions/141351/how-do-i-find-what-is-using-memory-in-a-python-process-in-a-production-system/61260839#61260839
dejlek commentedon May 21, 2020
Did you read what I wrote above? :) - It is not a regular memory leak!
Celery leaves large objects in Redis with TTL=-1 and eventually Redis runs out of memory over time! We found this "the hard way" few days ago, and wrote a maintenance script that runs every week to cleanup...
I humbly believe setting TTL=-1 for those keys is a bug.
jheld commentedon May 24, 2020
Anything related to the result expires setting? Perhaps you made the setting None so all the tasks for that worker keep their results in the backend (until TTL or eviction).
Can you provide more info?
dejlek commentedon May 26, 2020
No, we do not use the
result_expiressetting. It should be at its default (1 day if I remember). I checked anyway withinspect confand there was no result_expires in the output.gautamp8 commentedon Jan 17, 2021
This seems to be same as celery/kombu#294
We're also experiencing the same issue
auvipy commentedon Jan 17, 2021
sorry for not being meaningfully helpful! do you have the bandwidth to come up with a workable solution to the problem? after you come with a PR we could share our effort with you.
linar-jether commentedon Oct 25, 2022
Our solution to this issue is to periodically remove keys that have been idle for more than X days
humitos commentedon Feb 7, 2023
We are hitting this issue as well. I've been trying to debug it but I wasn't able to understand the root cause yet. I'm trying to plot some of the data I have access to.
This keys are never cleanup and we are manually deleting them once in a while --each week more frequently, tho.
Not sure if related or not, but it seems our Redis gets OOM when we receive a bunch of tasks at the same time:
We are using:
Is there any other important info I should be provide to help. I'm happy to keep debugging this, but I'd probably need more directions here. Note that we are only noticing this in production.
Edit: after 1h it went from 283Mb to 726Mb of
pidboxkeys.8 remaining items
harniruthwik commentedon Jul 14, 2023
We are facing similar issue, Can some help with the final workable solution ?
Fix celery healthcheck memory leak
Fix celery healthcheck memory leak
jonhilgart22 commentedon Jan 14, 2025
Also running into this, will set a cron to clear keys for now...
dejlek commentedon Jan 26, 2025
I've just had a production issue because 2+ GB sized *.reply.celery.pidbox keys consumed all available Redis memory...
ffje commentedon Feb 21, 2025
Hey, I'm willing to attempt to fix that and would appreciate any help on getting the root cause clarified.
As far as I understood there are 2 TTLs in place on the Queue:
and it seems like to fix the issue discussed here it would be sufficient to cover only channel expiration case for redis within kombu. however, to keep the feature complete it might be beneficial to implement message_ttl support as well.
If my understanding is correct the celery/kombu#1431 should cover both expires and message_ttl so moving the discussion in that issue. Would appreciate any confirmation that my conclusions make any sense.
james-ecd commentedon Mar 31, 2026
We're still seeing this in production. I noticed celery/kombu#2251 was merged but it doesn't appear to have resolved the issue for us. Is anyone else still experiencing this?
auvipy commentedon Apr 1, 2026
that kombu change is not released yet