Skip to content

Commit

Permalink
moving withResource call to the beginning of requestNode
Browse files Browse the repository at this point in the history
  • Loading branch information
shashitnak committed Apr 11, 2023
1 parent 039a83d commit bc79b73
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Database/Redis/Cluster.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit bc79b73

Please sign in to comment.