Repository navigation
Blocking command timeout cannot exceed client's socket_timeout #2807
Description
Version: What redis-py and what redis version is the issue happening on?
- redis-py:
4.5.5 - redis:
6.2.12
Platform: What platform / version? (For example Python 3.5.1 on Windows 7 / Ubuntu 15.10 / Azure)
- Python:
3.10.11, insidepython:3.10docker image
Description: Description of your issue, stack traces from errors and code that reproduces the issue
It seems that the timeout parameter to various blocking calls (specifically .brpop() in my case) cannot be longer than socket_timeout, otherwise a redis.exceptions.TimeoutError will be raised.
NOTE: My application actually uses redis.asyncio.client.Redis, but this behavior can be reproduced with the sync client too, as shown below.
Am I incorrect in thinking these timeouts should be more independent?... i.e: The socket timeout is "low-level", and the BRPOP timeout is "application-level"... regardless of what happens at the socket layer, the BRPOP timeout requested should be honored.
At present, the "If timeout is 0, then block indefinitely." statement in the docs appears to be untrue, because at some point you'll hit the socket timeout and get an exception that needs to be handled - which can also be demonstrated below by swapping for r.brpop('my_key', timeout=0).
root@a30c563c33a3:/# pip install redis
[...]
root@a30c563c33a3:/# python3
Python 3.10.11 (main, May 4 2023, 06:08:16) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from redis import Redis
>>> r = Redis(host='10.192.0.3', socket_timeout=4)
>>> r.ping()
True
>>> r.brpop('my_key', timeout=8)
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/redis/connection.py", line 210, in _read_from_socket
data = self._sock.recv(socket_read_size)
TimeoutError: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.10/site-packages/redis/commands/core.py", line 2587, in brpop
return self.execute_command("BRPOP", *keys)
File "/usr/local/lib/python3.10/site-packages/redis/client.py", line 1269, in execute_command
return conn.retry.call_with_retry(
File "/usr/local/lib/python3.10/site-packages/redis/retry.py", line 49, in call_with_retry
fail(error)
File "/usr/local/lib/python3.10/site-packages/redis/client.py", line 1273, in <lambda>
lambda error: self._disconnect_raise(conn, error),
File "/usr/local/lib/python3.10/site-packages/redis/client.py", line 1259, in _disconnect_raise
raise error
File "/usr/local/lib/python3.10/site-packages/redis/retry.py", line 46, in call_with_retry
return do()
File "/usr/local/lib/python3.10/site-packages/redis/client.py", line 1270, in <lambda>
lambda: self._send_command_parse_response(
File "/usr/local/lib/python3.10/site-packages/redis/client.py", line 1246, in _send_command_parse_response
return self.parse_response(conn, command_name, **options)
File "/usr/local/lib/python3.10/site-packages/redis/client.py", line 1286, in parse_response
response = connection.read_response()
File "/usr/local/lib/python3.10/site-packages/redis/connection.py", line 874, in read_response
response = self._parser.read_response(disable_decoding=disable_decoding)
File "/usr/local/lib/python3.10/site-packages/redis/connection.py", line 347, in read_response
result = self._read_response(disable_decoding=disable_decoding)
File "/usr/local/lib/python3.10/site-packages/redis/connection.py", line 357, in _read_response
raw = self._buffer.readline()
File "/usr/local/lib/python3.10/site-packages/redis/connection.py", line 260, in readline
self._read_from_socket()
File "/usr/local/lib/python3.10/site-packages/redis/connection.py", line 223, in _read_from_socket
raise TimeoutError("Timeout reading from socket")
redis.exceptions.TimeoutError: Timeout reading from socket
Activity
github-actions commentedon Jun 27, 2024
This issue is marked stale. It will be closed in 30 days if it is not updated.
meshantz commentedon Aug 12, 2024
Please don't close. We are experiencing this same issue.
awoimbee commentedon Mar 13, 2025
I am having the same issue with
pubsub.get_message(timeout=None), this is surprising behavior!I think the correct way to fix this is to use
health_check_intervaland notsocket_timeout.github-actions commentedon Mar 19, 2026
This issue has been automatically marked as stale due to inactivity.
It will be closed in 30 days if no further activity occurs.
If you believe this issue is still relevant, please add a comment to keep it open.
github-actions commentedon Apr 18, 2026
This issue has been automatically closed due to inactivity.
If you believe this issue is still relevant, please reopen it or create a new issue with updated information.
petyaslavova commentedon May 28, 2026
This should be fixed!
Stunned1 commentedon Jun 22, 2026
Hi, @petyaslavova ! I've been looking into this issue and wanted to comment before writing any code.
I noticed the 8.0.0 release notes document this as a known limitation, but I also see it's still being actively referenced as an unresolved root cause in recent bug reports like #4125. I wanted to ask, is the team open to a proper fix, or is the current guidance to adjust socket_timeout to be at least as long as the blocking command's timeout?
If a PR would be welcome, I'd love to start with the sync client for brpop and blpop as a first PR.
I'm fairly new to open source contributing, so I'd appreciate any guidance on the right approach before I dig in. :)
Fix blocking commands timeout when blocking_timeout exceeds socket_ti…