-
-
Notifications
You must be signed in to change notification settings - Fork 930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Prevent redis task loss when closing connection while in poll #1733
Conversation
@pawl can you try this? |
@auvipy Like test this as a fix for?: celery/celery#7276 I tried testing this fix on this branch of a minimal celery example: https://github.com/pawl/celery_pyamqp_memory_leak/tree/test_1733 I'm still seeing the issue with redis connection errors eventually causing it to remove the wrong function from We're probably still going to need a fix like this: #1734 |
@@ -1079,6 +1079,11 @@ def _purge(self, queue): | |||
|
|||
def close(self): | |||
self._closing = True | |||
if self._in_poll: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we try some integration tests for the changes as well? https://github.com/celery/kombu/blob/main/t/integration/test_redis.py
Thanks for fixing this issue. But it looks like this patch does not fix all possible edge cages. Adding a step Do you have any idea what to do in this case? |
Hi @mbierma, I am trying to debug #1785. Pardon my ignorance, but why does attempting to read the response before closing the channel allow the task to be restored before the channel is closed?
|
you are welcome to come with a better fix which handle the other edge cases as well. contributions are welcome |
Summary of issue
The redis poller uses the BRPOP command to pull items from the queue:
If the channel is closed before the
BRPOP
response is read, there is a risk that a task will be popped from the queue, but never picked up or restored:Summary of change
If the channel is in the _in_poll state when it is closed (i.e. or waiting for the
BRPOP
command to return), attempt to read theBRPOP
response before closing the channel. This should allow the task to be restored before the channel is closed.Potentially related issues