From 819757046a665ba482c9884985b3b626a3493703 Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Fri, 27 Nov 2020 12:53:41 +0100 Subject: [PATCH] Better thread handling when starting main node action `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. --- cardano-node/src/Cardano/Node/Run.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cardano-node/src/Cardano/Node/Run.hs b/cardano-node/src/Cardano/Node/Run.hs index 02aa10bbc6a..a5c615bc17f 100644 --- a/cardano-node/src/Cardano/Node/Run.hs +++ b/cardano-node/src/Cardano/Node/Run.hs @@ -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 =