@@ -127,6 +127,11 @@ import Control.Distributed.Process
127127 , monitorNode
128128 , unmonitor
129129 , NodeMonitorNotification(..)
130+ , finally
131+ , newChan
132+ , receiveChan
133+ , nsend
134+ , SendPort
130135 )
131136import qualified Control.Distributed.Process.Node as Node
132137 ( LocalNode
@@ -349,7 +354,19 @@ startMaster backend proc = do
349354 Node.runProcess node $ do
350355 slaves <- findSlaves backend
351356 redirectLogsHere backend
352− proc slaves
357+ proc slaves `finally` shutdownLogger
358+
359+--
360+-- | shut down the logger process. This ensures that any pending
361+-- messages are flushed before the process exits.
362+--
363+shutdownLogger :: Process ()
364+shutdownLogger = do
365+ (sport,rport) <- newChan
366+ nsend "logger" (sport :: SendPort ())
367+ receiveChan rport
368+ -- TODO: we should monitor the logger process so we don't deadlock if
369+ -- it has already died.
353370
354371--------------------------------------------------------------------------------
355372-- Accessors --