git.iko.soy/distributed-process
on master help sign in
Fix a bug in the built-in log file tracer
a2754c7Tim Watson
src/Control/Distributed/Process/Internal/Trace/Tracer.hs+8−6
@@ -20,6 +20,7 @@ import Control.Distributed.Process.Internal.CQueue
20 )
20 )
21import Control.Distributed.Process.Internal.Primitives
21import Control.Distributed.Process.Internal.Primitives
22 ( catch
22 ( catch
23+ , finally
23 , die
24 , die
24 , receiveWait
25 , receiveWait
25 , forward
26 , forward
@@ -27,6 +28,7 @@ import Control.Distributed.Process.Internal.Primitives
27 , match
28 , match
28 , matchAny
29 , matchAny
29 , matchAnyIf
30 , matchAnyIf
31+ , matchIf
30 , handleMessage
32 , handleMessage
31 , matchUnknown
33 , matchUnknown
32 , whereis
34 , whereis
@@ -163,16 +165,16 @@ logfileTracer p = do
163 liftIO $ putStrLn $ "writing to " ++ (show p)
165 liftIO $ putStrLn $ "writing to " ++ (show p)
164 h <- liftIO $ openFile p AppendMode
166 h <- liftIO $ openFile p AppendMode
165 liftIO $ hSetBuffering h LineBuffering
167 liftIO $ hSetBuffering h LineBuffering
166− logger h `catch` (\(_ :: SomeException) -> liftIO $ hClose h)
168+ logger h `finally` (liftIO $ hClose h)
167 where
169 where
168 logger :: Handle -> Process ()
170 logger :: Handle -> Process ()
169 logger h' = forever' $ do
171 logger h' = forever' $ do
170 receiveWait [
172 receiveWait [
171− matchAnyIf (\ev -> case ev of
173+ matchIf (\ev -> case ev of
172− TraceEvDisable -> True
174+ TraceEvDisable -> True
173− (TraceEvTakeover _) -> True
175+ (TraceEvTakeover _) -> True
174− _ -> False)
176+ _ -> False)
175− (\_ -> (liftIO $ hClose h') >> die "trace stopped")
177+ (\_ -> (liftIO $ hClose h') >> die "trace stopped")
176 , matchAny (\ev -> handleMessage ev (writeTrace h'))
178 , matchAny (\ev -> handleMessage ev (writeTrace h'))
177 ]
179 ]
178
180