-
Notifications
You must be signed in to change notification settings - Fork 2.6k
A deadlock is encountered when invoking the 'subscribe' function. #2883
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
Comments
@andymccurdy I have same deadlock problem with redis as celery broker
Can we bring back RLock? |
I think that during getting new connection, garbage collector delete PubSub causing this situation. |
Running into same issue when using Redis as backend for celery. |
def patch_redis_connectionpool_lock():
from hashlib import sha256
from inspect import getsource
import threading
from redis.connection import ConnectionPool
OLD_METHOD_SHA = ( # pylint: disable=invalid-name
b"some hash"
)
def reset(self):
self._lock = threading.RLock() # pylint: disable=protected-access
self._created_connections = 0 # pylint: disable=protected-access
self._available_connections = [] # pylint: disable=protected-access
self._in_use_connections = set() # pylint: disable=protected-access
# this must be the last operation in this method. while reset() is
# called when holding _fork_lock, other threads in this process
# can call _checkpid() which compares self.pid and os.getpid() without
# holding any lock (for performance reasons). keeping this assignment
# as the last operation ensures that those other threads will also
# notice a pid difference and block waiting for the first thread to
# release _fork_lock. when each of these threads eventually acquire
# _fork_lock, they will notice that another thread already called
# reset() and they will immediately release _fork_lock and continue on.
self.pid = os.getpid()
assert OLD_METHOD_SHA == sha256(getsource(ConnectionPool.reset).encode()).digest()
ConnectionPool.reset = reset For now I patched this method to previous working implementation till someone merge my MR. |
BTW, I still ran into deadlocking issues even with RLock, so I am not sure if its the culprit. My setup is using Redis as Celery backend and having lots of coroutines awaiting the AsyncResult.ready and AsyncResult.get. |
Version:
redis-py 4.5.5 used in a multi-threads program
Platform:
Python 3.9.7 on Linux 5.10 aarch64
Description:
At times, invoking the 'subscribe' function may result in a hang, and based on the stack analysis, it appears that a deadlock might be occurring.
Client is created with:
My program:
The text was updated successfully, but these errors were encountered: