Skip to content

Commit

Permalink
CAD-792 withShutdownHandler: set severity
Browse files Browse the repository at this point in the history
  • Loading branch information
deepfire authored and dcoutts committed Apr 8, 2020
1 parent 45d2a06 commit b1880fa
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions cardano-node/src/Cardano/Node/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ import Cardano.BM.Data.BackendKind (BackendKind (..))
import Cardano.BM.Data.LogItem (LOContent (..),
PrivacyAnnotation (..), mkLOMeta)
import Cardano.BM.Data.Tracer (ToLogObject (..),
TracingVerbosity (..))
TracingVerbosity (..), TracingFormatting (..),
severityNotice, trTransformer)
import Cardano.BM.Data.Transformers (setHostname)
import Cardano.BM.Trace

Expand Down Expand Up @@ -205,7 +206,7 @@ handleSimpleNode p trace nodeTracers npm onKernel = do
Left err -> (putTextLn $ show err) >> exitFailure
Right addr -> return addr

withShutdownHandler npm tracer $
withShutdownHandler npm trace $
Node.run
(consensusTracers nodeTracers)
(protocolTracers nodeTracers)
Expand Down Expand Up @@ -332,22 +333,27 @@ handleSimpleNode p trace nodeTracers npm onKernel = do
-- either deliberatly by the parent process or automatically because the parent
-- process itself terminated, then we initiate a clean shutdown.
--
withShutdownHandler :: NodeProtocolMode -> Tracer IO String -> IO () -> IO ()
withShutdownHandler :: NodeProtocolMode -> Trace IO Text -> IO () -> IO ()
withShutdownHandler (RealProtocolMode NodeCLI{shutdownIPC = Just (Fd fd)})
tracer action =
trace action =
Async.race_ (wrapUninterruptableIO waitForEOF) action
where
waitForEOF :: IO ()
waitForEOF = do
hnd <- IO.fdToHandle fd
r <- try $ IO.hGetChar hnd
case r of
Left e | IO.isEOFError e -> traceWith tracer "received shutdown request"
| otherwise -> throwIO e
Left e
| IO.isEOFError e -> traceWith tracer "received shutdown request"
| otherwise -> throwIO e

Right _ ->
throwIO $ IO.userError "--shutdown-ipc FD does not expect input"

tracer :: Tracer IO Text
tracer = trTransformer TextualRepresentation MaximalVerbosity
(severityNotice trace)

withShutdownHandler _ _ action = action

-- | Windows blocking file IO calls like 'hGetChar' are not interruptable by
Expand Down

0 comments on commit b1880fa

Please sign in to comment.