redis/redis-py · error · TimeoutError
Timeout reading from {host_error}
Error message
Timeout reading from {host_error} What it means
Raised as a TimeoutError in read_response when socket.timeout fires while reading a response from the server. Unless disconnect_on_error is False, the connection is disconnected first. It means the server did not send a complete response within socket_timeout.
Source
Thrown at redis/connection.py:1419
"""Read the response from a previously sent command"""
host_error = self._host_error()
try:
if self.protocol in ["3", 3]:
response = self._parser.read_response(
disable_decoding=disable_decoding,
push_request=push_request,
timeout=timeout,
)
else:
response = self._parser.read_response(
disable_decoding=disable_decoding, timeout=timeout
)
except socket.timeout:
if disconnect_on_error:
self.disconnect()
raise TimeoutError(f"Timeout reading from {host_error}")
except OSError as e:
if disconnect_on_error:
self.disconnect()
raise ConnectionError(f"Error while reading from {host_error} : {e.args}")
except BaseException:
# Also by default close in case of BaseException. A lot of code
# relies on this behaviour when doing Command/Response pairs.
# See #1128.
if disconnect_on_error:
self.disconnect()
raise
if self.health_check_interval:
self.next_health_check = time.monotonic() + self.health_check_interval
if isinstance(response, ResponseError):
try:
raise responseView on GitHub (pinned to da03cdc7e8)
Solutions
- Increase socket_timeout to exceed your longest expected command.
- For blocking commands, pass an explicit per-call timeout to read_response so the read timeout is intentional.
- Set retry_on_timeout=True to auto-retry idempotent commands.
- Avoid holding connections during long server-side pauses.
Example fix
// before
r = redis.Redis(host=h, socket_timeout=1.0)
r.blpop('queue') # blocks longer than 1s
// after
r = redis.Redis(host=h, socket_timeout=10.0)
r.blpop('queue') Defensive patterns
Strategy: retry
Try / catch
from redis.exceptions import TimeoutError
try:
val = r.get('k')
except TimeoutError as e:
if 'reading from' in str(e):
# only retry idempotent commands
val = r.get('k') Prevention
- Raise socket_timeout above the slowest expected command.
- For blocking commands, pass an explicit read timeout.
- Enable retry_on_timeout=True for idempotent operations.
When it happens
Trigger: Executing a command (or blocking command like BLPOP with no timeout, or a slow Lua script) that takes longer than socket_timeout to produce a response. read_response enforces socket_timeout on the read.
Common situations: Blocking commands (BLPOP, BRPOP, WAIT) outlasting socket_timeout; long-running EVAL scripts; server paused for persistence (BGSAVE fsync) or a DEBUG SLEEP; slow large-value responses; too-aggressive socket_timeout.
Related errors
- Timeout reading from {host_error}
- Timed out closing connection after {self.socket_connect_time
- Timeout writing to socket
- Error while reading from {host_error}: {e.args}
- Error while reading from {host_error} : {e.args}
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/44b2c0ff2a6232e6.json.
Report an issue: GitHub.