Skip to content

Commit

Permalink
different error on portinuse
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Jul 17, 2024
1 parent 1b3332d commit 5b6dc81
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
12 changes: 12 additions & 0 deletions cardano-testnet/src/Testnet/Process/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ initiateProcess cp = do
. register $ IO.cleanupProcess (mhStdin, mhStdout, mhStderr, hProcess)
return (mhStdin, mhStdout, mhStderr, hProcess, releaseKey)

--
-- retryOnAddrAlreadyInUseError
-- :: MonadIO m
-- => MT.DiffTime
-- -> MT.DiffTime
-- -> ExceptT ProcessError m a
-- -> ExceptT ProcessError m a
-- retryOnAddrAlreadyInUseError timeout interval act =
-- case runExceptT act of
-- Left Proce


-- We can throw an IOException from createProcess or an ResourceCleanupException from the ResourceT monad
resourceAndIOExceptionHandlers :: Applicative m => [Handler m ProcessError]
resourceAndIOExceptionHandlers = [ Handler $ pure . ProcessIOException
Expand Down
15 changes: 12 additions & 3 deletions cardano-testnet/src/Testnet/Runtime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import Data.Aeson.Encode.Pretty (encodePretty)
import Data.Algorithm.Diff
import Data.Algorithm.DiffOutput
import qualified Data.ByteString.Lazy.Char8 as BSC
import Data.List (intercalate)
import Data.List (intercalate, isInfixOf)
import qualified Data.List as List
import GHC.Exts (IsString (..))
import GHC.Stack
Expand Down Expand Up @@ -73,16 +73,24 @@ data NodeStartFailure
| ExecutableRelatedFailure ExecutableError
| FileRelatedFailure IOException
| NodeExecutableError (Doc Ann)
| NodeAddressAlreadyInUse (Doc Ann)
-- | NodePortNotOpenError IOException
| MaxSprocketLengthExceededError
deriving Show

mkNodeNonEmptyStderrError :: String -> NodeStartFailure
mkNodeNonEmptyStderrError stderr' = do
if "Address already in use" `isInfixOf` stderr'
then NodeAddressAlreadyInUse $ pretty stderr'
else NodeExecutableError $ pretty stderr'

instance Error NodeStartFailure where
prettyError = \case
ProcessRelatedFailure e -> "Cannot initiate process:" <+> pshow e
ExecutableRelatedFailure e -> "Cannot run cardano-node executable" <+> pshow e
FileRelatedFailure e -> "File error:" <+> prettyException e
NodeExecutableError e -> "Cardano node process did not start:" <+> unAnnotate e
NodeAddressAlreadyInUse e -> "Cardano node process did not start - address already in use:" <+> unAnnotate e
MaxSprocketLengthExceededError -> "Max sprocket length exceeded"

-- TODO: We probably want a check that this node has the necessary config files to run and
Expand Down Expand Up @@ -149,6 +157,7 @@ startNode tp node ipv4 port mPortReleaseKey testnetMagic nodeCmd = GHC.withFroze
H.note_ $ "Waiting for port " <> show port <> " to be released before starting node"
H.assertM $ Ping.waitForPortClosed 30 0.1 port

-- TODO: use isAlreadyInUseError
(Just stdIn, _, _, hProcess, _)
<- firstExceptT ProcessRelatedFailure $ initiateProcess
$ nodeProcess
Expand All @@ -172,8 +181,8 @@ startNode tp node ipv4 port mPortReleaseKey testnetMagic nodeCmd = GHC.withFroze

-- If we do have anything on stderr, fail.
stdErrContents <- liftIO $ IO.readFile nodeStderrFile
unless (null stdErrContents)
$ left . NodeExecutableError $ pretty stdErrContents
unless (null stdErrContents) $
throwError $ mkNodeNonEmptyStderrError stdErrContents

-- No stderr and no socket? Fail.
firstExceptT
Expand Down

0 comments on commit 5b6dc81

Please sign in to comment.