@@ -42,7 +42,6 @@ import qualified Data.Set as Set
4242import Data.Foldable (forM_)
4343import Data.Maybe (isJust, isNothing, catMaybes)
4444import Data.Typeable (Typeable)
45−import Debug.Trace
4645import Control.Category ((>>>))
4746import Control.Applicative ((<$>))
4847import Control.Monad (void, when)
@@ -63,7 +62,9 @@ import Control.Distributed.Process.Internal.StrictMVar
6362 , takeMVar
6463 )
6564import Control.Concurrent.Chan (newChan, writeChan, readChan)
66−import Control.Concurrent.STM (atomically)
65+import Control.Concurrent.STM
66+ ( atomically
67+ )
6768import Control.Distributed.Process.Internal.CQueue
6869 ( CQueue
6970 , enqueue
@@ -98,6 +99,7 @@ import Control.Distributed.Process.Internal.Types
9899 , LocalProcessId(..)
99100 , ProcessId(..)
100101 , LocalNode(..)
102+ , Tracer
101103 , LocalNodeState(..)
102104 , LocalProcess(..)
103105 , LocalProcessState(..)
@@ -141,6 +143,12 @@ import Control.Distributed.Process.Internal.Types
141143 , firstNonReservedProcessId
142144 , ImplicitReconnect(WithImplicitReconnect, NoImplicitReconnect)
143145 )
146+import Control.Distributed.Process.Internal.Trace
147+ ( trace
148+ , traceFormat
149+ , defaultTracer
150+ , stopTracer
151+ )
144152import Control.Distributed.Process.Serializable (Serializable)
145153import Control.Distributed.Process.Internal.Messaging
146154 ( sendBinary
@@ -192,11 +200,13 @@ createBareLocalNode endPoint rtable = do
192200 , _localPidUnique = unq
193201 , _localConnections = Map.empty
194202 }
203+ tracer <- defaultTracer
195204 ctrlChan <- newChan
196205 let node = LocalNode { localNodeId = NodeId $ NT.address endPoint
197206 , localEndPoint = endPoint
198207 , localState = state
199208 , localCtrlChan = ctrlChan
209+ , localTracer = tracer
200210 , remoteTable = rtable
201211 }
202212 void . forkIO $ runNodeController node
@@ -219,13 +229,6 @@ startServiceProcesses node = do
219229 sendChan ch ()
220230 ]
221231
222−-- | Send a message to the GHC event log
223−logEvent :: String -> IO ()
224−logEvent = traceEventIO
225−
226−logExit :: ProcessId -> DiedReason -> IO ()
227−logExit p r = logEvent $ (show p) ++ " exited: " ++ (show r)
228−
229232-- | Force-close a local node
230233--
231234-- TODO: for now we just close the associated endpoint
@@ -272,9 +275,6 @@ forkProcess node proc = modifyMVar (localState node) startProcess
272275 (runLocalProcess lproc proc >> return DiedNormal)
273276 (return . DiedException . (show :: SomeException -> String))
274277
275− -- [Issue #104]
276− logExit pid reason
277−
278278 -- [Unified: Table 4, rules termination and exiting]
279279 modifyMVar_ (localState node) (cleanupProcess pid)
280280 writeChan (localCtrlChan node) NCMsg
@@ -442,11 +442,12 @@ handleIncomingMessages node = go initConnectionState
442442 fail "Cloud Haskell fatal error: received unexpected multicast"
443443
444444 invalidRequest :: NT.ConnectionId -> ConnectionState -> IO ()
445− invalidRequest cid st =
445+ invalidRequest cid st = do
446446 -- TODO: We should treat this as a fatal error on the part of the remote
447447 -- node. That is, we should report the remote node as having died, and we
448448 -- should close incoming connections (this requires a Transport layer
449449 -- extension).
450+ traceEventFmtIO node "" ["[network] invalid request: ", (show cid)]
450451 go ( incomingAt cid ^= Nothing
451452 $ st
452453 )
@@ -498,6 +499,36 @@ instance Show ProcessKillException where
498499 show (ProcessKillException pid reason) =
499500 "killed-by=" ++ show pid ++ ",reason=" ++ reason
500501
502+--------------------------------------------------------------------------------
503+-- Tracing/Debugging --
504+--------------------------------------------------------------------------------
505+
506+-- [Issue #104]
507+
508+traceNotifyDied :: LocalNode -> Identifier -> DiedReason -> NC ()
509+traceNotifyDied node ident reason =
510+ traceNcEventFmt node " " ["[node-controller]", (show ident), (show reason)]
511+
512+traceNcEvent :: LocalNode -> String -> NC ()
513+traceNcEvent node msg = liftIO $ traceEventIO node msg
514+
515+traceNcEventFmt :: LocalNode -> String -> [String] -> NC ()
516+traceNcEventFmt node fmt args =
517+ liftIO $ traceEventFmtIO node fmt args
518+
519+traceEventIO :: LocalNode -> String -> IO ()
520+traceEventIO node msg = withLocalTracer node $ \t -> trace t msg
521+
522+traceEventFmtIO :: LocalNode
523+ -> String
524+ -> [String]
525+ -> IO ()
526+traceEventFmtIO node fmt args =
527+ withLocalTracer node $ \t -> traceFormat t fmt args
528+
529+withLocalTracer :: LocalNode -> (Tracer -> IO ()) -> IO ()
530+withLocalTracer node act = act (localTracer node)
531+
501532--------------------------------------------------------------------------------
502533-- Core functionality --
503534--------------------------------------------------------------------------------
@@ -605,6 +636,7 @@ ncEffectUnmonitor from ref = do
605636ncEffectDied :: Identifier -> DiedReason -> NC ()
606637ncEffectDied ident reason = do
607638 node <- ask
639+ traceNotifyDied node ident reason
608640 (affectedLinks, unaffectedLinks) <- gets (splitNotif ident . (^. links))
609641 (affectedMons, unaffectedMons) <- gets (splitNotif ident . (^. monitors))
610642
@@ -647,7 +679,6 @@ ncEffectDied ident reason = do
647679 , ctrlMsgSignal = Died ident reason
648680 }
649681
650−
651682-- [Unified: Table 13]
652683ncEffectSpawn :: ProcessId -> Closure (Process ()) -> SpawnRef -> NC ()
653684ncEffectSpawn pid cProc ref = do
@@ -849,18 +880,18 @@ notifyDied dest src reason mRef = do
849880
850881-- | [Unified: Table 8]
851882destNid :: ProcessSignal -> Maybe NodeId
852−destNid (Link ident) = Just $ nodeOf ident
853−destNid (Unlink ident) = Just $ nodeOf ident
854−destNid (Monitor ref) = Just $ nodeOf (monitorRefIdent ref)
855−destNid (Unmonitor ref) = Just $ nodeOf (monitorRefIdent ref)
856−destNid (Spawn _ _) = Nothing
857−destNid (Register _ _ _ _) = Nothing
858−destNid (WhereIs _) = Nothing
859−destNid (NamedSend _ _) = Nothing
883+destNid (Link ident) = Just $ nodeOf ident
884+destNid (Unlink ident) = Just $ nodeOf ident
885+destNid (Monitor ref) = Just $ nodeOf (monitorRefIdent ref)
886+destNid (Unmonitor ref) = Just $ nodeOf (monitorRefIdent ref)
887+destNid (Spawn _ _) = Nothing
888+destNid (Register _ _ _ _) = Nothing
889+destNid (WhereIs _) = Nothing
890+destNid (NamedSend _ _) = Nothing
860891-- We don't need to forward 'Died' signals; if monitoring/linking is setup,
861892-- then when a local process dies the monitoring/linking machinery will take
862893-- care of notifying remote nodes
863−destNid (Died _ _) = Nothing
894+destNid (Died _ _) = Nothing
864895destNid (Kill pid _) = Just $ processNodeId pid
865896destNid (Exit pid _) = Just $ processNodeId pid
866897destNid (GetInfo pid) = Just $ processNodeId pid