The Fix
pip install redis==7.1.0
Based on closed redis/redis-py issue #2624 · PR/commit linked
@@ -1385,10 +1385,16 @@ async def execute(self, raise_on_error: bool = True):
try:
- return await conn.retry.call_with_retry(
- lambda: execute(conn, stack, raise_on_error),
- lambda error: self._disconnect_raise_reset(conn, error),
import asyncio
from redis.asyncio import Redis
import sys
async def main():
myhost, mypassword = sys.argv[1:]
async with Redis(host=myhost, password=mypassword, ssl=True, single_connection_client=True) as r:
await r.set('foo', 'foo')
await r.set('bar', 'bar')
t = asyncio.create_task(r.get('foo'))
await asyncio.sleep(0.001)
t.cancel()
try:
await t
print('try again, we did not cancel the task in time')
except asyncio.CancelledError:
print('managed to cancel the task, connection is left open with unread response')
print('bar:', await r.get('bar'))
print('ping:', await r.ping())
print('foo:', await r.get('foo'))
if __name__ == '__main__':
asyncio.run(main())
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.0\nWhen NOT to use: Do not use this fix if the connection state management is handled differently in your application.\n\n
Why This Fix Works in Production
- Trigger: async with Redis(host=myhost, password=mypassword, ssl=True, single_connection_client=True) as r:
- Mechanism: Canceling an async Redis command leaves the connection in an unsafe state for future commands
- Why the fix works: Addresses an async Redis command cancellation issue that leaves the connection in an unsafe state for future commands. (first fixed release: 7.1.0).
- If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).
Why This Breaks in Prod
- Shows up under Python 3.8 in real deployments (not just unit tests).
- Canceling an async Redis command leaves the connection in an unsafe state for future commands
- Production symptom (often without a traceback): async with Redis(host=myhost, password=mypassword, ssl=True, single_connection_client=True) as r:
Proof / Evidence
- GitHub issue: #2624
- Fix PR: https://github.com/redis/redis-py/pull/2641
- First fixed release: 7.1.0
- Reproduced locally: No (not executed)
- Last verified: 2026-02-07
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.58
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“I wonder how much OpenAI/ChatGPT is funding maintenance of this library. 🤔”
“Yep, that's the one, and the #2641 has not fixed it fully, as I already commented here: https://github.com/redis/redis-py/pull/2641#issuecomment-1479957187 I am asking for this ticket to…”
“Is it the problem about OpenAI https://openai.com/blog/march-20-chatgpt-outage ?”
“Folks, I reopened this accidentally - but wanted to ensure there was communication that is clear. Please note - we're tracking in #2665. Let's align…”
Failure Signature (Search String)
- async with Redis(host=myhost, password=mypassword, ssl=True, single_connection_client=True) as r:
- except asyncio.CancelledError:
Copy-friendly signature
Failure Signature
-----------------
async with Redis(host=myhost, password=mypassword, ssl=True, single_connection_client=True) as r:
except asyncio.CancelledError:
Error Message
Signature-only (no traceback captured)
Error Message
-------------
async with Redis(host=myhost, password=mypassword, ssl=True, single_connection_client=True) as r:
except asyncio.CancelledError:
Minimal Reproduction
import asyncio
from redis.asyncio import Redis
import sys
async def main():
myhost, mypassword = sys.argv[1:]
async with Redis(host=myhost, password=mypassword, ssl=True, single_connection_client=True) as r:
await r.set('foo', 'foo')
await r.set('bar', 'bar')
t = asyncio.create_task(r.get('foo'))
await asyncio.sleep(0.001)
t.cancel()
try:
await t
print('try again, we did not cancel the task in time')
except asyncio.CancelledError:
print('managed to cancel the task, connection is left open with unread response')
print('bar:', await r.get('bar'))
print('ping:', await r.ping())
print('foo:', await r.get('foo'))
if __name__ == '__main__':
asyncio.run(main())
Environment
- Python: 3.8
What Broke
Subsequent commands on the same connection may read responses from previously canceled commands, causing unexpected behavior.
Why It Broke
Canceling an async Redis command leaves the connection in an unsafe state for future commands
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install redis==7.1.0
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/2641
First fixed release: 7.1.0
Last verified: 2026-02-07. Validate in your environment.
When NOT to Use This Fix
- Do not use this fix if the connection state management is handled differently in your application.
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 TLS smoke test that performs a real handshake in CI (include CA bundle validation and hostname checks).
- Alert on handshake failures by error string and endpoint to catch cert/CA changes quickly.
- 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.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.