Skip to content

Commit 52a8711

Browse files
committed
Retry once on Redis connection errors.
These errors may be transient, and there's no point killing the whole pod if that's the case.
1 parent 1e0ea28 commit 52a8711

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

python/activator/activator.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@
8989
bucket_notification_kafka_offset_reset = os.environ.get("BUCKET_NOTIFICATION_KAFKA_OFFSET_RESET", "latest")
9090
# Max requests to handle before restarting. 0 means no limit.
9191
max_requests = int(os.environ.get("WORKER_RESTART_FREQ", 0))
92+
# The number of seconds to delay retrying connections to the Redis stream.
93+
redis_retry = float(os.environ.get("REDIS_RETRY_DELAY", 30))
9294

9395
# Conditionally load keda environment variables
9496
if platform == "keda":
@@ -234,7 +236,12 @@ def _make_redis_streams_client(self):
234236
redis_client : `redis.Redis`
235237
Initialized Redis client.
236238
"""
237-
return redis.Redis(host=self.host)
239+
policy = redis.retry.Retry(redis.backoff.ConstantBackoff(redis_retry),
240+
1,
241+
# Bare ConnectionError covers things like DNS problems
242+
(redis.exceptions.ConnectionError, ),
243+
)
244+
return redis.Redis(host=self.host, retry=policy)
238245

239246
@staticmethod
240247
def _close_on_error(func):

0 commit comments

Comments
 (0)