The Fix
pip install redis==7.1.0
Based on closed redis/redis-py issue #1833 · PR/commit linked
Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.
@@ -604,7 +604,9 @@ def connect(self):
return
try:
- sock = self._connect()
+ sock = self.retry.call_with_retry(
+ lambda: self._connect(), lambda error: self.disconnect(error)
from redis.backoff import ExponentialBackoff
from redis.retry import Retry
from redis.client import Redis
from redis.exceptions import (
BusyLoadingError,
ConnectionError,
TimeoutError
)
retry = Retry(ExponentialBackoff(), 3) // Run 3 retries with exponential backoff strategy
r = Redis(host='localhost', port=6379, retry=retry, retry_on_error=[BusyLoadingError, ConnectionError, TimeoutError])
r_only_timeout = Redis(host='localhost', port=6379, retry=retry, retry_on_timeout=True)
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 retry mechanism is not desired for connection attempts.\n\n
Why This Fix Works in Production
- Trigger: Question: resolving hostname when retry on connection timeout
- Mechanism: The retry mechanism for socket timeouts did not apply when connecting to the server
- Why the fix works: Added a retry mechanism for socket timeouts when connecting to the server, allowing the hostname to be resolved again upon connection failure. (first fixed release: 7.1.0).
- If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.
Why This Breaks in Prod
- The retry mechanism for socket timeouts did not apply when connecting to the server
- Production symptom (often without a traceback): Question: resolving hostname when retry on connection timeout
Proof / Evidence
- GitHub issue: #1833
- Fix PR: https://github.com/redis/redis-py/pull/1895
- 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.55
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Yes, By setting retry_on_timeout=True, when timeoutError is thrown, the client disconnects its current connection and creates a new one”
“Thank you @ugatenio for catching that, you're right. I have created a new PR (#1895) to support retrying when connecting to the server.”
“@barshaul thanks for your replay. Another question - how many retries and what is the delay between each retry?”
“@barshaul I tried the solution you suggested and it's not working when trying to connect to the server. by reading the code I saw that…”
Failure Signature (Search String)
- Question: resolving hostname when retry on connection timeout
- I wonder if Redis client resolve again the hostname if connection timeout occurred while setting `retry_on_timeout=True`.
Copy-friendly signature
Failure Signature
-----------------
Question: resolving hostname when retry on connection timeout
I wonder if Redis client resolve again the hostname if connection timeout occurred while setting `retry_on_timeout=True`.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Question: resolving hostname when retry on connection timeout
I wonder if Redis client resolve again the hostname if connection timeout occurred while setting `retry_on_timeout=True`.
Minimal Reproduction
from redis.backoff import ExponentialBackoff
from redis.retry import Retry
from redis.client import Redis
from redis.exceptions import (
BusyLoadingError,
ConnectionError,
TimeoutError
)
retry = Retry(ExponentialBackoff(), 3) // Run 3 retries with exponential backoff strategy
r = Redis(host='localhost', port=6379, retry=retry, retry_on_error=[BusyLoadingError, ConnectionError, TimeoutError])
r_only_timeout = Redis(host='localhost', port=6379, retry=retry, retry_on_timeout=True)
What Broke
Connection attempts fail without retrying on socket timeouts, leading to outages.
Why It Broke
The retry mechanism for socket timeouts did not apply when connecting to the server
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/1895
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 retry mechanism is not desired for connection attempts.
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
- Make timeouts explicit and test them (unit + integration) to avoid silent behavior changes.
- Instrument retries (attempt count + reason) and alert on spikes to catch dependency slowdowns.
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.