Description
Hi again!
I just updated redis-py from 5.2.1 to 5.3.0 and I noticed that while adding the Dispatchers
there was deadlock introduced.
Summary
When using a client with Retries
enabled and subscribing to a pattern using psubscribe
, a deadlock can occur under certain conditions:
- If a
punsubscribe
is attempted and a disconnection (such as a broken pipe) happens during this process, a reconnection is triggered (via thePubSub._execute
error handling). - During reconnection, the client tries to re-subscribe to the previously subscribed patterns, but this process can result in a deadlock.
Full explanation
There was a new lock introduced before each PubSub
command execution on commit 40e5fc1
, which is part of the 5.3.0 release:
Lines 874 to 875 in 7130e1a
When a command execution fails, if Retries
are enabled, there will be a reconnection attempt:
Lines 895 to 916 in 7130e1a
However, when executing the connect
we get to the final lines where the resubscriptions callbacks are triggered for pubsub
:
Lines 406 to 413 in 7130e1a
This will hit the same lock again a cause a deadlock.
Let me know if you need any other information. 🙂