From 65a4dc111f08ba939e75276240f5969b5fc2abda Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 29 May 2024 11:41:28 +0200 Subject: [PATCH] add default retry config needed to handle connection resets --- jupyterhub_traefik_proxy/redis.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/jupyterhub_traefik_proxy/redis.py b/jupyterhub_traefik_proxy/redis.py index d3b26af9..738b2e13 100644 --- a/jupyterhub_traefik_proxy/redis.py +++ b/jupyterhub_traefik_proxy/redis.py @@ -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: