From 7b45605d45078b3614da15828f9550def7d21cb6 Mon Sep 17 00:00:00 2001 From: Leif Battermann Date: Wed, 5 Jun 2024 12:49:35 +0000 Subject: [PATCH] Use connection timeout when connecting to each node of a cluster --- src/Database/Redis/Connection.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Database/Redis/Connection.hs b/src/Database/Redis/Connection.hs index 156662ec..d68b791e 100644 --- a/src/Database/Redis/Connection.hs +++ b/src/Database/Redis/Connection.hs @@ -227,13 +227,15 @@ connectCluster bootstrapConnInfo = do shardMap <- shardMapFromClusterSlotsResponse slots newMVar shardMap commandInfos <- runRedisInternal conn command + let timeoutOptUs = + round . (1000000 *) <$> connectTimeout bootstrapConnInfo case commandInfos of Left e -> throwIO $ ClusterConnectError e Right infos -> do #if MIN_VERSION_resource_pool(0,3,0) - pool <- newPool (defaultPoolConfig (Cluster.connect infos shardMapVar Nothing) Cluster.disconnect (realToFrac $ connectMaxIdleTime bootstrapConnInfo) (connectMaxConnections bootstrapConnInfo)) + pool <- newPool (defaultPoolConfig (Cluster.connect infos shardMapVar timeoutOptUs) Cluster.disconnect (realToFrac $ connectMaxIdleTime bootstrapConnInfo) (connectMaxConnections bootstrapConnInfo)) #else - pool <- createPool (Cluster.connect infos shardMapVar Nothing) Cluster.disconnect 1 (connectMaxIdleTime bootstrapConnInfo) (connectMaxConnections bootstrapConnInfo) + pool <- createPool (Cluster.connect infos shardMapVar timeoutOptUs) Cluster.disconnect 1 (connectMaxIdleTime bootstrapConnInfo) (connectMaxConnections bootstrapConnInfo) #endif return $ ClusteredConnection shardMapVar pool