diff --git a/src/Network/Rpc/Connection.hs b/src/Network/Rpc/Connection.hs index 1b0efca773311605ed65ca960c4315b837fba7e0..24fefa8396665fb2108c2238deda763dda06170d 100644 --- a/src/Network/Rpc/Connection.hs +++ b/src/Network/Rpc/Connection.hs @@ -76,9 +76,9 @@ connectTCP host port = do -- The 'raceConnections'-async is 'link'ed to this thread, so 'readMVar' is interrupted when all connection attempts fail sock <- (withAsync (interruptible raceConnections) (link >=> const (readMVar sockMVar)) + -- As soon as we have an open connection, stop spawning more connections `finally` (mapM_ (cancel . snd) =<< readMVar connectTasksMVar)) `onException` (mapM_ Socket.close =<< tryTakeMVar sockMVar) - -- As soon as we have an open connection, stop spawning more connections pure sock where hints :: Socket.AddrInfo