Skip to content

Commit c0ac10d

Browse files
Classic298claude
andauthored
fix: honor REDIS_SOCKET_CONNECT_TIMEOUT on non-sentinel clients (open-webui#23572)
* fix(redis): honor REDIS_SOCKET_CONNECT_TIMEOUT on non-sentinel clients Previously only the sentinel path passed REDIS_SOCKET_CONNECT_TIMEOUT through to the Redis client. Plain redis:// and cluster URLs fell back to redis-py's default (no explicit connect timeout), so a hung Redis or a black-holed network path could stall the whole worker until the kernel gave up. Forwarding the same env var to from_url()/RedisCluster keeps the behavior consistent across all deployment topologies. * fix(redis): gate socket_connect_timeout on is-not-None, not truthiness Addresses review feedback: the truthiness check on REDIS_SOCKET_CONNECT_TIMEOUT silently dropped an explicit 0 value and was inconsistent with the sentinel construction path, which forwards the value directly. Switch to `is not None` so any user-configured value (including 0) is passed through to from_url() and RedisCluster.from_url(). --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent faf935e commit c0ac10d

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

backend/open_webui/utils/redis.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ def get_redis_connection(
191191

192192
connection = None
193193

194+
connect_timeout_kwargs = (
195+
{'socket_connect_timeout': REDIS_SOCKET_CONNECT_TIMEOUT}
196+
if REDIS_SOCKET_CONNECT_TIMEOUT is not None
197+
else {}
198+
)
199+
194200
if async_mode:
195201
import redis.asyncio as redis
196202

@@ -214,9 +220,17 @@ def get_redis_connection(
214220
elif redis_cluster:
215221
if not redis_url:
216222
raise ValueError('Redis URL must be provided for cluster mode.')
217-
return redis.cluster.RedisCluster.from_url(redis_url, decode_responses=decode_responses)
223+
return redis.cluster.RedisCluster.from_url(
224+
redis_url,
225+
decode_responses=decode_responses,
226+
**connect_timeout_kwargs,
227+
)
218228
elif redis_url:
219-
connection = redis.from_url(redis_url, decode_responses=decode_responses)
229+
connection = redis.from_url(
230+
redis_url,
231+
decode_responses=decode_responses,
232+
**connect_timeout_kwargs,
233+
)
220234
else:
221235
import redis
222236

@@ -239,9 +253,17 @@ def get_redis_connection(
239253
elif redis_cluster:
240254
if not redis_url:
241255
raise ValueError('Redis URL must be provided for cluster mode.')
242-
return redis.cluster.RedisCluster.from_url(redis_url, decode_responses=decode_responses)
256+
return redis.cluster.RedisCluster.from_url(
257+
redis_url,
258+
decode_responses=decode_responses,
259+
**connect_timeout_kwargs,
260+
)
243261
elif redis_url:
244-
connection = redis.Redis.from_url(redis_url, decode_responses=decode_responses)
262+
connection = redis.Redis.from_url(
263+
redis_url,
264+
decode_responses=decode_responses,
265+
**connect_timeout_kwargs,
266+
)
245267

246268
_CONNECTION_CACHE[cache_key] = connection
247269
return connection

0 commit comments

Comments
 (0)