{"id":"44b2c0ff2a6232e6","repo":"redis/redis-py","slug":"timeout-reading-from-host-error-44b2c0","errorCode":null,"errorMessage":"Timeout reading from {host_error}","messagePattern":"Timeout reading from (.+?)","errorType":"exception","errorClass":"TimeoutError","httpStatus":null,"severity":"error","filePath":"redis/connection.py","lineNumber":1419,"sourceCode":"        \"\"\"Read the response from a previously sent command\"\"\"\n\n        host_error = self._host_error()\n\n        try:\n            if self.protocol in [\"3\", 3]:\n                response = self._parser.read_response(\n                    disable_decoding=disable_decoding,\n                    push_request=push_request,\n                    timeout=timeout,\n                )\n            else:\n                response = self._parser.read_response(\n                    disable_decoding=disable_decoding, timeout=timeout\n                )\n        except socket.timeout:\n            if disconnect_on_error:\n                self.disconnect()\n            raise TimeoutError(f\"Timeout reading from {host_error}\")\n        except OSError as e:\n            if disconnect_on_error:\n                self.disconnect()\n            raise ConnectionError(f\"Error while reading from {host_error} : {e.args}\")\n        except BaseException:\n            # Also by default close in case of BaseException.  A lot of code\n            # relies on this behaviour when doing Command/Response pairs.\n            # See #1128.\n            if disconnect_on_error:\n                self.disconnect()\n            raise\n\n        if self.health_check_interval:\n            self.next_health_check = time.monotonic() + self.health_check_interval\n\n        if isinstance(response, ResponseError):\n            try:\n                raise response","sourceCodeStart":1401,"sourceCodeEnd":1437,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/connection.py#L1401-L1437","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nr = redis.Redis(host=h, socket_timeout=1.0)\nr.blpop('queue')  # blocks longer than 1s\n// after\nr = redis.Redis(host=h, socket_timeout=10.0)\nr.blpop('queue')","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from redis.exceptions import TimeoutError\ntry:\n    val = r.get('k')\nexcept TimeoutError as e:\n    if 'reading from' in str(e):\n        # only retry idempotent commands\n        val = r.get('k')","preventionTips":["Raise socket_timeout above the slowest expected command.","For blocking commands, pass an explicit read timeout.","Enable retry_on_timeout=True for idempotent operations."],"tags":["network","timeout","read","blocking-command"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}