Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry logic for port checks #1630

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/Internal/Plutip/Server.purs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Cardano.Types.PrivateKey (PrivateKey(PrivateKey))
import Contract.Chain (waitNSlots)
import Contract.Config (defaultSynchronizationParams, defaultTimeParams)
import Contract.Monad (Contract, ContractEnv, liftContractM, runContractInEnv)
import Control.Alternative (guard)
import Control.Monad.Error.Class (liftEither, throwError)
import Control.Monad.State (State, execState, modify_)
import Control.Monad.Trans.Class (lift)
Expand Down Expand Up @@ -102,6 +103,7 @@ import Effect.Aff.Class (liftAff)
import Effect.Aff.Retry
( RetryPolicy
, constantDelay
, exponentialBackoff
, limitRetriesByCumulativeDelay
, recovering
)
Expand Down Expand Up @@ -438,16 +440,22 @@ configCheck cfg = do
, cfg.ogmiosConfig.port /\ "ogmios"
, cfg.kupoConfig.port /\ "kupo"
]
occupiedServices <- Array.catMaybes <$> for services \(port /\ service) -> do
isPortAvailable port <#> if _ then Nothing else Just (port /\ service)
unless (Array.null occupiedServices) do
liftEffect $ throw $
"Unable to run the following services, because the ports are occupied:\
\\n" <> foldMap printServiceEntry occupiedServices
totalDelay = 10000.00
retryPolicy = limitRetriesByCumulativeDelay (Milliseconds totalDelay) $
exponentialBackoff (Milliseconds 100.0)
recovering retryPolicy [ \_ _ -> pure true ] \_ -> do
occupiedServices <- Array.catMaybes <$> for services \service@(port /\ _) ->
do
isPortAvailable port <#> \isAvailable -> Just service <* guard
(not isAvailable)
unless (Array.null occupiedServices) do
liftEffect $ throw $
"Unable to run the following services, because the ports are occupied:\
\\n" <> foldMap printServiceEntry occupiedServices
where
printServiceEntry :: UInt /\ String -> String
printServiceEntry (port /\ service) =
"- " <> service <> " (port: " <> show (UInt.toInt port) <> ")\n"
printServiceEntry (port /\ name) =
"- " <> name <> " (port: " <> show (UInt.toInt port) <> ")\n"

-- | Start the plutip cluster, initializing the state with the given
-- | UTxO distribution. Also initializes an extra payment key (aka
Expand Down