The Fix
pip install redis==7.1.1
Based on closed redis/redis-py issue #3847 · PR/commit linked
Production note: This tends to surface only under concurrency. Reproduce with load tests and watch for lock contention/cancellation paths.
@@ -263,16 +263,27 @@ async def owned(self) -> bool:
return self.local.token is not None and stored_token == self.local.token
- def release(self) -> Awaitable[None]:
- """Releases the already acquired lock"""
+ async def release(self) -> None:
await lock.acquire()
release_task = asyncio.create_task(lock.release())
release_task.cancel()
try:
await release_task
except asyncio.CancelledError:
pass
await lock.locked() # => returns True
await lock.owned() # => returns False
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\npip install redis==7.1.1\nWhen NOT to use: This fix is not applicable if the lock is not used in an async context.\n\n
Why This Fix Works in Production
- Trigger: Async lock can enter a deadlock if it is cancelled while being released
- Mechanism: Fixes a deadlock issue in redis.asyncio.Lock when release() is cancelled.
- Why the fix works: Fixes a deadlock issue in redis.asyncio.Lock when release() is cancelled. (first fixed release: 7.1.1).
- If left unfixed, failures can be intermittent under concurrency (hard to reproduce; shows up as sporadic 5xx/timeouts).
Why This Breaks in Prod
- Production symptom (often without a traceback): Async lock can enter a deadlock if it is cancelled while being released
Proof / Evidence
- GitHub issue: #3847
- Fix PR: https://github.com/redis/redis-py/pull/3900
- First fixed release: 7.1.1
- Reproduced locally: No (not executed)
- Last verified: 2026-02-08
- Confidence: 0.70
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.55
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Hi @liavt, thanks for bringing this up! We will have a look at it.”
Failure Signature (Search String)
- Async lock can enter a deadlock if it is cancelled while being released
- Currently, the implementation of `redis.asyncio.Lock` can enter a deadlock state if `release()` is cancelled. This is due to the Lock resetting it's internal token before running
Copy-friendly signature
Failure Signature
-----------------
Async lock can enter a deadlock if it is cancelled while being released
Currently, the implementation of `redis.asyncio.Lock` can enter a deadlock state if `release()` is cancelled. This is due to the Lock resetting it's internal token before running the actual release function.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Async lock can enter a deadlock if it is cancelled while being released
Currently, the implementation of `redis.asyncio.Lock` can enter a deadlock state if `release()` is cancelled. This is due to the Lock resetting it's internal token before running the actual release function.
Minimal Reproduction
await lock.acquire()
release_task = asyncio.create_task(lock.release())
release_task.cancel()
try:
await release_task
except asyncio.CancelledError:
pass
await lock.locked() # => returns True
await lock.owned() # => returns False
What Broke
Cancelling release() during execution could leave the async lock in an inconsistent deadlock state.
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install redis==7.1.1
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/redis/redis-py/pull/3900
First fixed release: 7.1.1
Last verified: 2026-02-08. Validate in your environment.
When NOT to Use This Fix
- This fix is not applicable if the lock is not used in an async context.
Verify Fix
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Add a stress test that runs high-concurrency workloads and fails on thread dumps / blocked locks.
- Enable watchdog dumps in prod (faulthandler, thread dump endpoint) to capture deadlocks quickly.
Version Compatibility Table
| Version | Status |
|---|---|
| 7.1.1 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.