From bc79b7303c0ad057904ef3c35709672b1515ca4e Mon Sep 17 00:00:00 2001 From: shashitnak Date: Mon, 10 Apr 2023 12:49:35 +0530 Subject: [PATCH] moving withResource call to the beginning of requestNode --- src/Database/Redis/Cluster.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Database/Redis/Cluster.hs b/src/Database/Redis/Cluster.hs index a9ae2910..247843c2 100644 --- a/src/Database/Redis/Cluster.hs +++ b/src/Database/Redis/Cluster.hs @@ -454,9 +454,9 @@ allMasterNodes (Connection nodeConns _ _ _ _) (ShardMap shardMap) = onlyMasterNodes = (\(Shard master _) -> master) <$> nub (IntMap.elems shardMap) requestNode :: NodeConnection -> [[B.ByteString]] -> IO [Reply] -requestNode (NodeConnection pool lastRecvRef _) requests = do +requestNode (NodeConnection pool lastRecvRef _) requests = withResource pool $ \ctx -> do envTimeout <- round . (\x -> (x :: Time.NominalDiffTime) * 1000000) . realToFrac . fromMaybe (0.5 :: Double) . (>>= readMaybe) <$> lookupEnv "REDIS_REQUEST_NODE_TIMEOUT" - eresp <- race (withResource pool requestNodeImpl) (threadDelay envTimeout) + eresp <- race (requestNodeImpl ctx) (threadDelay envTimeout) case eresp of Left e -> return e Right _ -> putStrLn "timeout happened" *> throwIO (TimeoutException "Request Timeout")