Skip to content

Commit

Permalink
add default retry config
Browse files Browse the repository at this point in the history
needed to handle connection resets
  • Loading branch information
minrk committed May 29, 2024
1 parent 9aafdc4 commit 65a4dc1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions jupyterhub_traefik_proxy/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ def _connect_redis(self):
port=port,
decode_responses=True,
)
if not any(key.startswith('retry') for key in self.redis_client_kwargs):
# default retry configuration, if no retry configuration provided

from redis.asyncio.retry import Retry
from redis.backoff import ExponentialBackoff
from redis.exceptions import BusyLoadingError, ConnectionError, TimeoutError

# works out to ~30 seconds, e.g. handling redis server restart
# sum(ExponentialBackoff(cap=5).compute(i) for i in range(15))
kwargs["retry"] = Retry(ExponentialBackoff(cap=5), 15)
kwargs["retry_on_error"] = [BusyLoadingError, ConnectionError, TimeoutError]
if self.redis_password:
kwargs["password"] = self.redis_password
if self.redis_username:
Expand Down

0 comments on commit 65a4dc1

Please sign in to comment.