-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Retry Mechanism Fails When Redis Container is Paused #3555
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
Comments
Hi! We would have a look on this in meantime |
Following up on this issue, I've noticed that it also occurs when a container is still booting up in the background, making the port available before the Redis instance has fully initialized. An improved approach for my Proposed solution would look like this: try:
ping_parts = self._command_packer.pack("PING")
for part in ping_parts:
sock.sendall(part)
response = sock.recv(7)
assert str_if_bytes(response).startswith("+PONG")
except Exception:
raise OSError(f"Redis handshake failed: {socket_address}") However, there are two small points that require consideration:
|
Hey @vladvildanov , I opened a PR with a solution to problem mentioned in the comment. if you want I can add you as a reviewer |
Expected behavior
When the Redis container is paused (not stopped), the connection attempt should fail, triggering the retry mechanism. The retry number should increase monotonically until until the specified maximum number of retries is reached.
Example logs of expected behavior:
The print statement was added at the end of the following
except
block:redis-py/redis/retry.py
Lines 60 to 70 in ea01a30
Actual behavior
Instead of progressing through the retry attempts, the retry mechanism gets stuck at the first attempt, repeating indefinitely.
Example logs of actual behavior:
Root Cause
The issue occurs because the
sock.connect
(line 575 of the_connect
method) succeeds even when the container ispaused
. However, subsequent read operations fail withTimeout
.redis-py/redis/connection.py
Lines 728 to 763 in ea01a30
Possible solution
To properly detect when the connection is truly established, we can send a
PING
command immediately afterconnect()
and verify the response.Add the following after
sock.connect()
to ensure the connection is functional:Additional Comments
There may be a better way to handle the read operation for the
PING
response using existing methods, but calling_send_ping
directly does not work in this case.This issue also affects the asynchronous version of
redis-py
.Let me know if you'd like a clearer example to reproduce the behavior.
The text was updated successfully, but these errors were encountered: