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

Question: resolving hostname when retry on connection timeout #1833

Closed
ugatenio opened this issue Dec 26, 2021 · 6 comments · Fixed by #1895
Closed

Question: resolving hostname when retry on connection timeout #1833

ugatenio opened this issue Dec 26, 2021 · 6 comments · Fixed by #1895

Comments

@ugatenio
Copy link

I wonder if Redis client resolve again the hostname if connection timeout occurred while setting retry_on_timeout=True.
I'm asking since sometime the mapping between hostname to ip can be invalid since the DNS changed the mapping.

@ugatenio ugatenio changed the title resolving hostname when retry on connection timeout Question: resolving hostname when retry on connection timeout Dec 26, 2021
@barshaul
Copy link
Contributor

barshaul commented Jan 2, 2022

Yes,
By setting retry_on_timeout=True, when timeoutError is thrown, the client disconnects its current connection and creates a new one. Upon creating a new connection, the hostname is resolved again.

To retry on other errors too, you can use the new argument retry_on_error and pass other error types in a list.

@ugatenio
Copy link
Author

ugatenio commented Jan 2, 2022

@barshaul thanks for your replay.
Another question - how many retries and what is the delay between each retry?

@barshaul
Copy link
Contributor

barshaul commented Jan 2, 2022

If you don't pass a Retry instance using the client's 'retry' argument, it will create a default one for you. The default Retry object has 1 retries and NoBackoff() strategy.

Here's more info about the Retry / Backoff strategies:

Example how to create a client with retry object:

from redis.backoff import ExponentialBackoff
from redis.retry import Retry
from redis.client import Redis
from redis.exceptions import (
    BusyLoadingError,
    ConnectionError,
    TimeoutError
)

retry = Retry(ExponentialBackoff(), 3) // Run 3 retries with exponential backoff strategy 
r = Redis(host='localhost', port=6379, retry=retry, retry_on_error=[BusyLoadingError, ConnectionError, TimeoutError])
r_only_timeout = Redis(host='localhost', port=6379, retry=retry, retry_on_timeout=True)

@ugatenio
Copy link
Author

ugatenio commented Jan 2, 2022

@barshaul Thank you!

@ugatenio
Copy link
Author

ugatenio commented Jan 20, 2022

@barshaul I tried the solution you suggested and it's not working when trying to connect to the server.
by reading the code I saw that the retry mechanism only apply at the command execution level and not when trying to connect to the server.

any suggestion?

@barshaul
Copy link
Contributor

Thank you @ugatenio for catching that, you're right.
I have created a new PR (#1895) to support retrying when connecting to the server.

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

Successfully merging a pull request may close this issue.

2 participants