@@ -42,7 +42,6 @@ import qualified Data.Set as Set
42import Data.Foldable (forM_)
42import Data.Foldable (forM_)
43import Data.Maybe (isJust, isNothing, catMaybes)
43import Data.Maybe (isJust, isNothing, catMaybes)
44import Data.Typeable (Typeable)
44import Data.Typeable (Typeable)
46import Control.Category ((>>>))
45import Control.Category ((>>>))
47import Control.Applicative ((<$>))
46import Control.Applicative ((<$>))
48import Control.Monad (void, when)
47import Control.Monad (void, when)
@@ -63,7 +62,9 @@ import Control.Distributed.Process.Internal.StrictMVar
63 , takeMVar
62 , takeMVar
65import Control.Concurrent.Chan (newChan, writeChan, readChan)
64import Control.Concurrent.Chan (newChan, writeChan, readChan)
66−import Control.Concurrent.STM (atomically)
65+import Control.Concurrent.STM
67import Control.Distributed.Process.Internal.CQueue
68import Control.Distributed.Process.Internal.CQueue
@@ -98,6 +99,7 @@ import Control.Distributed.Process.Internal.Types
98 , LocalProcessId(..)
99 , LocalProcessId(..)
99 , ProcessId(..)
100 , ProcessId(..)
100 , LocalNode(..)
101 , LocalNode(..)
101 , LocalNodeState(..)
103 , LocalNodeState(..)
102 , LocalProcess(..)
104 , LocalProcess(..)
103 , LocalProcessState(..)
105 , LocalProcessState(..)
@@ -141,6 +143,12 @@ import Control.Distributed.Process.Internal.Types
141 , firstNonReservedProcessId
143 , firstNonReservedProcessId
142 , ImplicitReconnect(WithImplicitReconnect, NoImplicitReconnect)
144 , ImplicitReconnect(WithImplicitReconnect, NoImplicitReconnect)
146+import Control.Distributed.Process.Internal.Trace
144import Control.Distributed.Process.Serializable (Serializable)
152import Control.Distributed.Process.Serializable (Serializable)
145import Control.Distributed.Process.Internal.Messaging
153import Control.Distributed.Process.Internal.Messaging
146 ( sendBinary
154 ( sendBinary
@@ -192,11 +200,13 @@ createBareLocalNode endPoint rtable = do
192 , _localPidUnique = unq
200 , _localPidUnique = unq
193 , _localConnections = Map.empty
201 , _localConnections = Map.empty
203+ tracer <- defaultTracer
195 ctrlChan <- newChan
204 ctrlChan <- newChan
196 let node = LocalNode { localNodeId = NodeId $ NT.address endPoint
205 let node = LocalNode { localNodeId = NodeId $ NT.address endPoint
197 , localEndPoint = endPoint
206 , localEndPoint = endPoint
198 , localState = state
207 , localState = state
199 , localCtrlChan = ctrlChan
208 , localCtrlChan = ctrlChan
209+ , localTracer = tracer
200 , remoteTable = rtable
210 , remoteTable = rtable
202 void . forkIO $ runNodeController node
212 void . forkIO $ runNodeController node
@@ -219,13 +229,6 @@ startServiceProcesses node = do
219 sendChan ch ()
229 sendChan ch ()
222−-- | Send a message to the GHC event log
223−logEvent :: String -> IO ()
224−logEvent = traceEventIO
226−logExit :: ProcessId -> DiedReason -> IO ()
227−logExit p r = logEvent $ (show p) ++ " exited: " ++ (show r)
229-- | Force-close a local node
232-- | Force-close a local node
231-- TODO: for now we just close the associated endpoint
234-- TODO: for now we just close the associated endpoint
@@ -272,9 +275,6 @@ forkProcess node proc = modifyMVar (localState node) startProcess
272 (runLocalProcess lproc proc >> return DiedNormal)
275 (runLocalProcess lproc proc >> return DiedNormal)
273 (return . DiedException . (show :: SomeException -> String))
276 (return . DiedException . (show :: SomeException -> String))
278 -- [Unified: Table 4, rules termination and exiting]
278 -- [Unified: Table 4, rules termination and exiting]
279 modifyMVar_ (localState node) (cleanupProcess pid)
279 modifyMVar_ (localState node) (cleanupProcess pid)
280 writeChan (localCtrlChan node) NCMsg
280 writeChan (localCtrlChan node) NCMsg
@@ -442,11 +442,12 @@ handleIncomingMessages node = go initConnectionState
442 fail "Cloud Haskell fatal error: received unexpected multicast"
442 fail "Cloud Haskell fatal error: received unexpected multicast"
444 invalidRequest :: NT.ConnectionId -> ConnectionState -> IO ()
444 invalidRequest :: NT.ConnectionId -> ConnectionState -> IO ()
445− invalidRequest cid st =
445+ invalidRequest cid st = do
446 -- TODO: We should treat this as a fatal error on the part of the remote
446 -- TODO: We should treat this as a fatal error on the part of the remote
447 -- node. That is, we should report the remote node as having died, and we
447 -- node. That is, we should report the remote node as having died, and we
448 -- should close incoming connections (this requires a Transport layer
448 -- should close incoming connections (this requires a Transport layer
449 -- extension).
449 -- extension).
450+ traceEventFmtIO node "" ["[network] invalid request: ", (show cid)]
450 go ( incomingAt cid ^= Nothing
451 go ( incomingAt cid ^= Nothing
@@ -498,6 +499,36 @@ instance Show ProcessKillException where
498 show (ProcessKillException pid reason) =
499 show (ProcessKillException pid reason) =
499 "killed-by=" ++ show pid ++ ",reason=" ++ reason
500 "killed-by=" ++ show pid ++ ",reason=" ++ reason
502+--------------------------------------------------------------------------------
503+-- Tracing/Debugging --
504+--------------------------------------------------------------------------------
508+traceNotifyDied :: LocalNode -> Identifier -> DiedReason -> NC ()
509+traceNotifyDied node ident reason =
510+ traceNcEventFmt node " " ["[node-controller]", (show ident), (show reason)]
512+traceNcEvent :: LocalNode -> String -> NC ()
513+traceNcEvent node msg = liftIO $ traceEventIO node msg
515+traceNcEventFmt :: LocalNode -> String -> [String] -> NC ()
516+traceNcEventFmt node fmt args =
517+ liftIO $ traceEventFmtIO node fmt args
519+traceEventIO :: LocalNode -> String -> IO ()
520+traceEventIO node msg = withLocalTracer node $ \t -> trace t msg
522+traceEventFmtIO :: LocalNode
526+traceEventFmtIO node fmt args =
527+ withLocalTracer node $ \t -> traceFormat t fmt args
529+withLocalTracer :: LocalNode -> (Tracer -> IO ()) -> IO ()
530+withLocalTracer node act = act (localTracer node)
501--------------------------------------------------------------------------------
532--------------------------------------------------------------------------------
502-- Core functionality --
533-- Core functionality --
503--------------------------------------------------------------------------------
534--------------------------------------------------------------------------------
@@ -605,6 +636,7 @@ ncEffectUnmonitor from ref = do
605ncEffectDied :: Identifier -> DiedReason -> NC ()
636ncEffectDied :: Identifier -> DiedReason -> NC ()
606ncEffectDied ident reason = do
637ncEffectDied ident reason = do
607 node <- ask
638 node <- ask
639+ traceNotifyDied node ident reason
608 (affectedLinks, unaffectedLinks) <- gets (splitNotif ident . (^. links))
640 (affectedLinks, unaffectedLinks) <- gets (splitNotif ident . (^. links))
609 (affectedMons, unaffectedMons) <- gets (splitNotif ident . (^. monitors))
641 (affectedMons, unaffectedMons) <- gets (splitNotif ident . (^. monitors))
@@ -647,7 +679,6 @@ ncEffectDied ident reason = do
647 , ctrlMsgSignal = Died ident reason
679 , ctrlMsgSignal = Died ident reason
651-- [Unified: Table 13]
682-- [Unified: Table 13]
652ncEffectSpawn :: ProcessId -> Closure (Process ()) -> SpawnRef -> NC ()
683ncEffectSpawn :: ProcessId -> Closure (Process ()) -> SpawnRef -> NC ()
653ncEffectSpawn pid cProc ref = do
684ncEffectSpawn pid cProc ref = do
@@ -849,18 +880,18 @@ notifyDied dest src reason mRef = do
850-- | [Unified: Table 8]
881-- | [Unified: Table 8]
851destNid :: ProcessSignal -> Maybe NodeId
882destNid :: ProcessSignal -> Maybe NodeId
852−destNid (Link ident) = Just $ nodeOf ident
883+destNid (Link ident) = Just $ nodeOf ident
853−destNid (Unlink ident) = Just $ nodeOf ident
884+destNid (Unlink ident) = Just $ nodeOf ident
854−destNid (Monitor ref) = Just $ nodeOf (monitorRefIdent ref)
885+destNid (Monitor ref) = Just $ nodeOf (monitorRefIdent ref)
855−destNid (Unmonitor ref) = Just $ nodeOf (monitorRefIdent ref)
886+destNid (Unmonitor ref) = Just $ nodeOf (monitorRefIdent ref)
856−destNid (Spawn _ _) = Nothing
887+destNid (Spawn _ _) = Nothing
857−destNid (Register _ _ _ _) = Nothing
888+destNid (Register _ _ _ _) = Nothing
858−destNid (WhereIs _) = Nothing
889+destNid (WhereIs _) = Nothing
859−destNid (NamedSend _ _) = Nothing
890+destNid (NamedSend _ _) = Nothing
860-- We don't need to forward 'Died' signals; if monitoring/linking is setup,
891-- We don't need to forward 'Died' signals; if monitoring/linking is setup,
861-- then when a local process dies the monitoring/linking machinery will take
892-- then when a local process dies the monitoring/linking machinery will take
862-- care of notifying remote nodes
893-- care of notifying remote nodes
863−destNid (Died _ _) = Nothing
894+destNid (Died _ _) = Nothing
864destNid (Kill pid _) = Just $ processNodeId pid
895destNid (Kill pid _) = Just $ processNodeId pid
865destNid (Exit pid _) = Just $ processNodeId pid
896destNid (Exit pid _) = Just $ processNodeId pid
866destNid (GetInfo pid) = Just $ processNodeId pid
897destNid (GetInfo pid) = Just $ processNodeId pid