From 567b0776cd4183f7aaa718ec16a736a48c70abcb Mon Sep 17 00:00:00 2001 From: Cevat Batuhan Tolon <85768122+ctolon@users.noreply.github.com> Date: Thu, 29 Jan 2026 16:13:03 +0300 Subject: [PATCH] REDIS_RECONNECT_DELAY as positive float for handle retry delay on timeout/connection errors (#21021) --- backend/open_webui/env.py | 16 ++++++++++++++++ backend/open_webui/utils/redis.py | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/backend/open_webui/env.py b/backend/open_webui/env.py index 42e872fca9..3fc75c72bb 100644 --- a/backend/open_webui/env.py +++ b/backend/open_webui/env.py @@ -392,6 +392,22 @@ try: REDIS_SOCKET_CONNECT_TIMEOUT = float(REDIS_SOCKET_CONNECT_TIMEOUT) except ValueError: REDIS_SOCKET_CONNECT_TIMEOUT = None + +REDIS_RECONNECT_DELAY = os.environ.get( + "REDIS_RECONNECT_DELAY", "" +) + +if REDIS_RECONNECT_DELAY == "": + REDIS_RECONNECT_DELAY = None +else: + try: + REDIS_RECONNECT_DELAY = float( + REDIS_RECONNECT_DELAY + ) + if REDIS_RECONNECT_DELAY < 0: + REDIS_RECONNECT_DELAY = None + except Exception: + REDIS_RECONNECT_DELAY = None #################################### # UVICORN WORKERS diff --git a/backend/open_webui/utils/redis.py b/backend/open_webui/utils/redis.py index 2040633a7b..fcc4879ba3 100644 --- a/backend/open_webui/utils/redis.py +++ b/backend/open_webui/utils/redis.py @@ -1,5 +1,7 @@ import inspect from urllib.parse import urlparse +import asyncio +import time import logging @@ -12,6 +14,7 @@ from open_webui.env import ( REDIS_SENTINEL_MAX_RETRY_COUNT, REDIS_SENTINEL_PORT, REDIS_URL, + REDIS_RECONNECT_DELAY, ) log = logging.getLogger(__name__) @@ -63,6 +66,8 @@ class SentinelRedisProxy: i + 1, REDIS_SENTINEL_MAX_RETRY_COUNT, ) + if REDIS_RECONNECT_DELAY: + time.sleep(REDIS_RECONNECT_DELAY / 1000) continue log.error( "Redis operation failed after %s retries: %s", @@ -94,6 +99,8 @@ class SentinelRedisProxy: i + 1, REDIS_SENTINEL_MAX_RETRY_COUNT, ) + if REDIS_RECONNECT_DELAY: + await asyncio.sleep(REDIS_RECONNECT_DELAY / 1000) continue log.error( "Redis operation failed after %s retries: %s", @@ -122,6 +129,8 @@ class SentinelRedisProxy: i + 1, REDIS_SENTINEL_MAX_RETRY_COUNT, ) + if REDIS_RECONNECT_DELAY: + time.sleep(REDIS_RECONNECT_DELAY / 1000) continue log.error( "Redis operation failed after %s retries: %s",