git.iko.soy/distributed-process
on master help sign in
Bugfix: continue after broken connection
dbb96c1Edsko de Vries
distributed-process/src/Control/Distributed/Process/Node.hs+28−23
@@ -21,10 +21,11 @@ import qualified Data.Map as Map
21 , delete
21 , delete
22 , toList
22 , toList
23 , partitionWithKey
23 , partitionWithKey
24+ , filterWithKey
24 )
25 )
25−import qualified Data.List as List (delete)
26+import qualified Data.List as List (delete, (\\))
26import Data.Set (Set)
27import Data.Set (Set)
27−import qualified Data.Set as Set (empty, insert, delete, member)
28+import qualified Data.Set as Set (empty, insert, delete, member, (\\), fromList)
28import Data.Foldable (forM_)
29import Data.Foldable (forM_)
29import Data.Maybe (isJust, fromMaybe)
30import Data.Maybe (isJust, fromMaybe)
30import Data.Typeable (Typeable)
31import Data.Typeable (Typeable)
@@ -321,13 +322,17 @@ handleIncomingMessages node = go [] Map.empty Map.empty Set.empty
321 (Map.delete cid procs)
322 (Map.delete cid procs)
322 (Map.delete cid chans)
323 (Map.delete cid chans)
323 (Set.delete cid ctrls)
324 (Set.delete cid ctrls)
324− NT.ErrorEvent (NT.TransportError (NT.EventConnectionLost (Just theirAddr) _) _) -> do
325+ NT.ErrorEvent (NT.TransportError (NT.EventConnectionLost (Just theirAddr) cids) _) -> do
325 -- [Unified table 9, rule node_disconnect]
326 -- [Unified table 9, rule node_disconnect]
326 let nid = NodeIdentifier $ NodeId theirAddr
327 let nid = NodeIdentifier $ NodeId theirAddr
327 writeChan ctrlChan NCMsg
328 writeChan ctrlChan NCMsg
328 { ctrlMsgSender = nid
329 { ctrlMsgSender = nid
329 , ctrlMsgSignal = Died nid DiedDisconnect
330 , ctrlMsgSignal = Died nid DiedDisconnect
330 }
331 }
332+ go (uninitConns List.\\ cids)
333+ (Map.filterWithKey (\k _ -> k `notElem` cids) procs)
334+ (Map.filterWithKey (\k _ -> k `notElem` cids) chans)
335+ (ctrls Set.\\ Set.fromList cids)
331 NT.ErrorEvent (NT.TransportError (NT.EventConnectionLost Nothing _) _) ->
336 NT.ErrorEvent (NT.TransportError (NT.EventConnectionLost Nothing _) _) ->
332 -- TODO: We should treat an asymetrical connection loss (incoming
337 -- TODO: We should treat an asymetrical connection loss (incoming
333 -- connection broken, but outgoing connection still potentially ok)
338 -- connection broken, but outgoing connection still potentially ok)
@@ -669,23 +674,23 @@ splitNotif :: Identifier
669 -> Map Identifier a
674 -> Map Identifier a
670 -> (Map Identifier a, Map Identifier a)
675 -> (Map Identifier a, Map Identifier a)
671splitNotif ident = Map.partitionWithKey (const . impliesDeathOf ident)
676splitNotif ident = Map.partitionWithKey (const . impliesDeathOf ident)
672− where
677+
673− -- | Does the death of one entity (node, project, channel) imply the death
678+-- | Does the death of one entity (node, project, channel) imply the death
674− -- of another?
679+-- of another?
675− impliesDeathOf :: Identifier -- ^ Who died
680+impliesDeathOf :: Identifier -- ^ Who died
676− -> Identifier -- ^ Who's being watched
681+ -> Identifier -- ^ Who's being watched
677− -> Bool -- ^ Does this death implies the death of the watchee?
682+ -> Bool -- ^ Does this death implies the death of the watchee?
678− NodeIdentifier nid `impliesDeathOf` NodeIdentifier nid' =
683+NodeIdentifier nid `impliesDeathOf` NodeIdentifier nid' =
679− nid' == nid
684+ nid' == nid
680− NodeIdentifier nid `impliesDeathOf` ProcessIdentifier pid =
685+NodeIdentifier nid `impliesDeathOf` ProcessIdentifier pid =
681− processNodeId pid == nid
686+ processNodeId pid == nid
682− NodeIdentifier nid `impliesDeathOf` SendPortIdentifier cid =
687+NodeIdentifier nid `impliesDeathOf` SendPortIdentifier cid =
683− processNodeId (sendPortProcessId cid) == nid
688+ processNodeId (sendPortProcessId cid) == nid
684− ProcessIdentifier pid `impliesDeathOf` ProcessIdentifier pid' =
689+ProcessIdentifier pid `impliesDeathOf` ProcessIdentifier pid' =
685− pid' == pid
690+ pid' == pid
686− ProcessIdentifier pid `impliesDeathOf` SendPortIdentifier cid =
691+ProcessIdentifier pid `impliesDeathOf` SendPortIdentifier cid =
687− sendPortProcessId cid == pid
692+ sendPortProcessId cid == pid
688− SendPortIdentifier cid `impliesDeathOf` SendPortIdentifier cid' =
693+SendPortIdentifier cid `impliesDeathOf` SendPortIdentifier cid' =
689− cid' == cid
694+ cid' == cid
690− _ `impliesDeathOf` _ =
695+_ `impliesDeathOf` _ =
691− False
696+ False