@@ -9,7 +9,7 @@ import Cardano.BM.Tracing (ToObject)
9
9
import CardanoNode (cliQueryProtocolParameters )
10
10
import Control.Concurrent.Async (forConcurrently_ )
11
11
import Control.Concurrent.Class.MonadSTM (modifyTVar' , newTVarIO , readTVarIO )
12
- import Control.Exception (IOException )
12
+ import Control.Exception (Handler ( .. ), IOException , catches )
13
13
import Control.Lens ((?~) )
14
14
import Control.Monad.Class.MonadAsync (forConcurrently )
15
15
import Data.Aeson (Value (.. ), object , (.=) )
@@ -31,7 +31,7 @@ import Hydra.Network qualified as Network
31
31
import Hydra.Options (ChainConfig (.. ), DirectChainConfig (.. ), LedgerConfig (.. ), RunOptions (.. ), defaultDirectChainConfig , toArgs )
32
32
import Network.HTTP.Req (GET (.. ), HttpException , JsonResponse , NoReqBody (.. ), POST (.. ), ReqBodyJson (.. ), defaultHttpConfig , responseBody , runReq , (/:) )
33
33
import Network.HTTP.Req qualified as Req
34
- import Network.WebSockets (Connection , receiveData , runClient , sendClose , sendTextData )
34
+ import Network.WebSockets (Connection , HandshakeException , receiveData , runClient , sendClose , sendTextData )
35
35
import System.FilePath ((<.>) , (</>) )
36
36
import System.IO.Temp (withSystemTempDirectory )
37
37
import System.Info (os )
@@ -369,18 +369,24 @@ withHydraNode' tracer chainConfig workDir hydraNodeId hydraSKey hydraVKeys allNo
369
369
, i /= hydraNodeId
370
370
]
371
371
372
- withConnectionToNode :: Tracer IO HydraNodeLog -> Int -> (HydraClient -> IO a ) -> IO a
372
+ withConnectionToNode :: forall a . Tracer IO HydraNodeLog -> Int -> (HydraClient -> IO a ) -> IO a
373
373
withConnectionToNode tracer hydraNodeId action = do
374
374
connectedOnce <- newIORef False
375
375
tryConnect connectedOnce (200 :: Int )
376
376
where
377
377
tryConnect connectedOnce n
378
378
| n == 0 = failure $ " Timed out waiting for connection to hydra-node " <> show hydraNodeId
379
- | otherwise =
380
- doConnect connectedOnce `catch` \ (e :: IOException ) -> do
381
- readIORef connectedOnce >>= \ case
382
- False -> threadDelay 0.1 >> tryConnect connectedOnce (n - 1 )
383
- True -> throwIO e
379
+ | otherwise = do
380
+ let
381
+ retryOrThrow :: forall proxy e . Exception e => proxy e -> e -> IO a
382
+ retryOrThrow _ e =
383
+ readIORef connectedOnce >>= \ case
384
+ False -> threadDelay 0.1 >> tryConnect connectedOnce (n - 1 )
385
+ True -> throwIO e
386
+ doConnect connectedOnce
387
+ `catches` [ Handler $ retryOrThrow (Proxy @ IOException )
388
+ , Handler $ retryOrThrow (Proxy @ HandshakeException )
389
+ ]
384
390
385
391
doConnect connectedOnce = runClient " 127.0.0.1" (4_000 + hydraNodeId) " /" $ \ connection -> do
386
392
atomicWriteIORef connectedOnce True
0 commit comments