Skip to content

Commit 2a09eba

Browse files
committed
trace-dispatcher: standardTracer without catch but with named thread
1 parent d8bb11b commit 2a09eba

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

trace-dispatcher/src/Cardano/Logging/Tracer/Standard.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ module Cardano.Logging.Tracer.Standard (
55
standardTracer
66
) where
77

8+
import Control.Concurrent (myThreadId)
89
import Control.Concurrent.Async
910
import Control.Concurrent.Chan.Unagi.Bounded
10-
import Control.Exception (BlockedIndefinitelyOnMVar, catch)
1111
import Control.Monad (forever, when)
1212
import Control.Monad.IO.Class
1313
import Data.IORef (IORef, modifyIORef', newIORef, readIORef)
1414
import Data.Maybe (isNothing)
1515
import Data.Text (Text)
1616
import qualified Data.Text.IO as TIO
17+
import GHC.Conc (labelThread)
1718
import System.IO (hFlush, stdout)
1819

1920
import Cardano.Logging.DocuGenerator
@@ -29,6 +30,8 @@ newtype StandardTracerState = StandardTracerState {
2930
emptyStandardTracerState :: StandardTracerState
3031
emptyStandardTracerState = StandardTracerState Nothing
3132

33+
-- | It is mandatory to construct only one standard tracer in any application!
34+
-- Throwing away a standard tracer and using a new one will result in an exception
3235
standardTracer :: forall m. (MonadIO m)
3336
=> m (Trace m FormattedMessage)
3437
standardTracer = do
@@ -66,9 +69,10 @@ standardTracer = do
6669
startStdoutThread :: IORef StandardTracerState -> IO ()
6770
startStdoutThread stateRef = do
6871
(inChan, outChan) <- newChan 2048
69-
as <- async (catch
70-
(stdoutThread outChan)
71-
(\(_ :: BlockedIndefinitelyOnMVar) -> pure ()))
72+
as <- async (do
73+
tid <- myThreadId
74+
labelThread tid "StdoutTrace"
75+
stdoutThread outChan)
7276
link as
7377
modifyIORef' stateRef (\ st ->
7478
st {stRunning = Just (inChan, outChan, as)})

0 commit comments

Comments
 (0)