Skip to content

Commit

Permalink
Merge #2135
Browse files Browse the repository at this point in the history
2135: Better thread handling when starting main node action r=coot a=coot

`handleSimpleNode` is a non-terminating function: it can only error.  We
need to use `finally` clause to ensure that an action runs when it
errors.  It is also more pragmatic to use `withAsync` to run peer list
logging action, this way it will be cancelled once `handleSimjpleNode`
errors.  Since we don't care if that action fails we do not await on its
termination.


Co-authored-by: Marcin Szamotulski <profunctor@pm.me>
  • Loading branch information
iohk-bors[bot] and coot committed Nov 27, 2020
2 parents 42ab46c + 8197570 commit 4aa93f4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cardano-node/src/Cardano/Node/Run.hs
Expand Up @@ -127,11 +127,14 @@ runNode cmdPc = do

tracers <- mkTracers (ncTraceConfig nc) trace nodeKernelData

peersThread <- Async.async $ handlePeersListSimple trace nodeKernelData
handleSimpleNode p trace tracers nc (setNodeKernel nodeKernelData)
Async.uninterruptibleCancel peersThread
Async.withAsync (handlePeersListSimple trace nodeKernelData)
$ \_peerLogingThread ->
-- We ignore peer loging thread if it dies, but it will be killed
-- when 'handleSimpleNode' terminates.
handleSimpleNode p trace tracers nc (setNodeKernel nodeKernelData)
`finally`
shutdownLoggingLayer loggingLayer

shutdownLoggingLayer loggingLayer

logTracingVerbosity :: NodeConfiguration -> Tracer IO String -> IO ()
logTracingVerbosity nc tracer =
Expand Down

0 comments on commit 4aa93f4

Please sign in to comment.