Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocking command timeout cannot exceed client's socket_timeout #2807

Open
attie-argentum opened this issue Jun 19, 2023 · 2 comments
Open

Blocking command timeout cannot exceed client's socket_timeout #2807

attie-argentum opened this issue Jun 19, 2023 · 2 comments
Labels

Comments

@attie-argentum
Copy link

attie-argentum commented Jun 19, 2023

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, inside python:3.10 docker 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
Copy link
Contributor

This issue is marked stale. It will be closed in 30 days if it is not updated.

@github-actions github-actions bot added the Stale label Jun 27, 2024
@meshantz
Copy link

Please don't close. We are experiencing this same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants