mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-11 20:05:19 +00:00
introduce REDIS_SOCKET_CONNECT_TIMEOUT to control Redis/Sentinel connection timeouts
This commit is contained in:
parent
492c8bac09
commit
4a0c572d59
3 changed files with 23 additions and 2 deletions
|
|
@ -395,6 +395,18 @@ try:
|
|||
except ValueError:
|
||||
REDIS_SENTINEL_MAX_RETRY_COUNT = 2
|
||||
|
||||
# Socket/Connect timeout for connections to Redis/Sentinel nodes
|
||||
REDIS_SOCKET_CONNECT_TIMEOUT = os.environ.get(
|
||||
"REDIS_SOCKET_CONNECT_TIMEOUT", "5"
|
||||
)
|
||||
try:
|
||||
if REDIS_SOCKET_CONNECT_TIMEOUT.lower() == "none":
|
||||
REDIS_SOCKET_CONNECT_TIMEOUT = None
|
||||
else:
|
||||
REDIS_SOCKET_CONNECT_TIMEOUT = max(float(REDIS_SOCKET_CONNECT_TIMEOUT), 0.0)
|
||||
except ValueError:
|
||||
REDIS_SOCKET_CONNECT_TIMEOUT = 5.0
|
||||
|
||||
####################################
|
||||
# UVICORN WORKERS
|
||||
####################################
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ from open_webui.env import (
|
|||
WEBSOCKET_SENTINEL_PORT,
|
||||
WEBSOCKET_SENTINEL_HOSTS,
|
||||
REDIS_KEY_PREFIX,
|
||||
REDIS_SOCKET_CONNECT_TIMEOUT,
|
||||
WEBSOCKET_REDIS_OPTIONS,
|
||||
WEBSOCKET_SERVER_PING_TIMEOUT,
|
||||
WEBSOCKET_SERVER_PING_INTERVAL,
|
||||
|
|
@ -62,17 +63,22 @@ REDIS = None
|
|||
SOCKETIO_CORS_ORIGINS = "*" if CORS_ALLOW_ORIGIN == ["*"] else CORS_ALLOW_ORIGIN
|
||||
|
||||
if WEBSOCKET_MANAGER == "redis":
|
||||
mgr_redis_options = {**WEBSOCKET_REDIS_OPTIONS} if WEBSOCKET_REDIS_OPTIONS else {}
|
||||
if "socket_connect_timeout" not in mgr_redis_options:
|
||||
mgr_redis_options["socket_connect_timeout"] = REDIS_SOCKET_CONNECT_TIMEOUT
|
||||
|
||||
if WEBSOCKET_SENTINEL_HOSTS:
|
||||
mgr = socketio.AsyncRedisManager(
|
||||
get_sentinel_url_from_env(
|
||||
WEBSOCKET_REDIS_URL, WEBSOCKET_SENTINEL_HOSTS, WEBSOCKET_SENTINEL_PORT
|
||||
),
|
||||
redis_options=WEBSOCKET_REDIS_OPTIONS,
|
||||
redis_options=mgr_redis_options,
|
||||
)
|
||||
else:
|
||||
mgr = socketio.AsyncRedisManager(
|
||||
WEBSOCKET_REDIS_URL, redis_options=WEBSOCKET_REDIS_OPTIONS
|
||||
WEBSOCKET_REDIS_URL, redis_options=mgr_redis_options
|
||||
)
|
||||
|
||||
sio = socketio.AsyncServer(
|
||||
cors_allowed_origins=SOCKETIO_CORS_ORIGINS,
|
||||
async_mode="asgi",
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ from open_webui.env import (
|
|||
REDIS_SENTINEL_MAX_RETRY_COUNT,
|
||||
REDIS_SENTINEL_PORT,
|
||||
REDIS_URL,
|
||||
REDIS_SOCKET_CONNECT_TIMEOUT,
|
||||
)
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
|
@ -162,6 +163,7 @@ def get_redis_connection(
|
|||
username=redis_config["username"],
|
||||
password=redis_config["password"],
|
||||
decode_responses=decode_responses,
|
||||
socket_connect_timeout=REDIS_SOCKET_CONNECT_TIMEOUT,
|
||||
)
|
||||
connection = SentinelRedisProxy(
|
||||
sentinel,
|
||||
|
|
@ -188,6 +190,7 @@ def get_redis_connection(
|
|||
username=redis_config["username"],
|
||||
password=redis_config["password"],
|
||||
decode_responses=decode_responses,
|
||||
socket_connect_timeout=REDIS_SOCKET_CONNECT_TIMEOUT,
|
||||
)
|
||||
connection = SentinelRedisProxy(
|
||||
sentinel,
|
||||
|
|
|
|||
Loading…
Reference in a new issue