redis-py icon indicating copy to clipboard operation
redis-py copied to clipboard

Client hangs for around 15 minutes during network hiccup although short socket_timeout is specified

Open jerry-git opened this issue 4 years ago • 2 comments

Version:

  • redis-py: 3.5.3

Platform:

  • Python 3.9.5

Description: Network hiccup results in ~15 minutes hang before TimeoutError is raised although socket_timeout is defined while instantiating the client.

The client is created like this:

from redis import StrictRedis

redis_client = StrictRedis.from_url(my_redis_url, socket_timeout=0.3, socket_connect_timeout=0.1)

During network hiccups, the client hangs for ~15 minutes (between 938-939 seconds to be exact) in hget before raising a TimeoutError. Stack trace of the exception (note that ddtrace is being used but I doubt it'd affect this):

 File \"/home/user/my-app/my-module.py\", line 99, in my_function\n    the_stuff_read_from_redis: Optional[bytes] = redis_client.hget('my-hash', 'my-key')\n
 File \"/home/user/.venv/lib/python3.9/site-packages/redis/client.py\", line 3010, in hget\n    return self.execute_command('HGET', name, key)\n
 File \"/home/user/.venv/lib/python3.9/site-packages/ddtrace/contrib/redis/patch.py\", line 85, in traced_execute_command\n    return func(*args, **kwargs)\n
 File \"/home/user/.venv/lib/python3.9/site-packages/redis/client.py\", line 901, in execute_command\n    return self.parse_response(conn, command_name, **options)\n
 File \"/home/user/.venv/lib/python3.9/site-packages/redis/client.py\", line 915, in parse_response\n    response = connection.read_response()\n
 File \"/home/user/.venv/lib/python3.9/site-packages/redis/connection.py\", line 739, in read_response\n    response = self._parser.read_response()\n
 File \"/home/user/.venv/lib/python3.9/site-packages/redis/connection.py\", line 470, in read_response\n    self.read_from_socket()\n
 File \"/home/user/.venv/lib/python3.9/site-packages/redis/connection.py\", line 442, in read_from_socket\n    raise TimeoutError(\"Timeout reading from socket\")\n"

Just to note, the Redis server and the client process are not running in the same machine. Also, I assume this is similar to https://github.com/andymccurdy/redis-py/issues/722 although there the consensus seemed to be that setting socket_timeout should help (and it's relatively old issue).

jerry-git avatar Jul 27 '21 09:07 jerry-git

Something similar is happening with celery beat which uses redis backend. The timing matches (938-939 second "breaks"). The difference is that there's no TimeoutError or any other exception present but I assume that's swallowed somewhere in the call stack (e.g. inside celery code). Related thread in the celery-users Google Group.

jerry-git avatar Jul 27 '21 09:07 jerry-git

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

github-actions[bot] avatar Jul 28 '22 00:07 github-actions[bot]