Fix: Add keep-alive options to Redis clients to prevent idle timeouts and socket closing. #4377
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem:
When Flowise is deployed with Redis (especially in Queue Mode or environments like Azure Cache for Redis with idle timeouts), Redis connections can be closed by the server after a period of inactivity (e.g., 10-15 minutes). This results in
uncaughtException: Socket closed unexpectedly
errors, crashing worker processes or causing failures in other Redis-dependent components.This issue is tracked in #2186.
Solution:
This PR adds keep-alive mechanisms to the Redis clients used throughout Flowise to ensure connections remain active even during idle periods. The following settings were added to the respective client configurations:
socket: { keepAlive: 60000 }
andpingInterval: 60000
to the clients used byRedisEventPublisher
andRedisEventSubscriber
.keepAlive: 60000
andenableReadyCheck: true
to theioredis
connection configuration used by BullMQ.ioredis
Clients: AddedkeepAlive: 60000
and a defaultretryStrategy
to clients used inCachePool
,RateLimiterManager
,RedisCache
,RedisEmbeddingsCache
, andRedisBackedChatMemory
nodes.@redis/client
Clients: Addedsocket: { keepAlive: 60000 }
andpingInterval: 60000
to the client used in theRedis
Vector Store node.The keep-alive/ping intervals are set to 60000ms (1 minute) as a robust default, significantly shorter than typical server timeouts, ensuring connections are maintained without excessive background traffic.
Testing:
--timeout 10
) idle timeout.Closes:
Fixes #2186