@@ -21,10 +21,11 @@ import qualified Data.Map as Map
2121 , delete
2222 , toList
2323 , partitionWithKey
24+ , filterWithKey
2425 )
25−import qualified Data.List as List (delete)
26+import qualified Data.List as List (delete, (\\))
2627import 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)
2829import Data.Foldable (forM_)
2930import Data.Maybe (isJust, fromMaybe)
3031import Data.Typeable (Typeable)
@@ -321,13 +322,17 @@ handleIncomingMessages node = go [] Map.empty Map.empty Set.empty
321322 (Map.delete cid procs)
322323 (Map.delete cid chans)
323324 (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
325326 -- [Unified table 9, rule node_disconnect]
326327 let nid = NodeIdentifier $ NodeId theirAddr
327328 writeChan ctrlChan NCMsg
328329 { ctrlMsgSender = nid
329330 , ctrlMsgSignal = Died nid DiedDisconnect
330331 }
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)
331336 NT.ErrorEvent (NT.TransportError (NT.EventConnectionLost Nothing _) _) ->
332337 -- TODO: We should treat an asymetrical connection loss (incoming
333338 -- connection broken, but outgoing connection still potentially ok)
@@ -669,23 +674,23 @@ splitNotif :: Identifier
669674 -> Map Identifier a
670675 -> (Map Identifier a, Map Identifier a)
671676splitNotif ident = Map.partitionWithKey (const . impliesDeathOf ident)
672− where
673− -- | Does the death of one entity (node, project, channel) imply the death
674− -- of another?
675− impliesDeathOf :: Identifier -- ^ Who died
676− -> Identifier -- ^ Who's being watched
677− -> Bool -- ^ Does this death implies the death of the watchee?
678− NodeIdentifier nid `impliesDeathOf` NodeIdentifier nid' =
679− nid' == nid
680− NodeIdentifier nid `impliesDeathOf` ProcessIdentifier pid =
681− processNodeId pid == nid
682− NodeIdentifier nid `impliesDeathOf` SendPortIdentifier cid =
683− processNodeId (sendPortProcessId cid) == nid
684− ProcessIdentifier pid `impliesDeathOf` ProcessIdentifier pid' =
685− pid' == pid
686− ProcessIdentifier pid `impliesDeathOf` SendPortIdentifier cid =
687− sendPortProcessId cid == pid
688− SendPortIdentifier cid `impliesDeathOf` SendPortIdentifier cid' =
689− cid' == cid
690− _ `impliesDeathOf` _ =
691− False
677+
678+-- | Does the death of one entity (node, project, channel) imply the death
679+-- of another?
680+impliesDeathOf :: Identifier -- ^ Who died
681+ -> Identifier -- ^ Who's being watched
682+ -> Bool -- ^ Does this death implies the death of the watchee?
683+NodeIdentifier nid `impliesDeathOf` NodeIdentifier nid' =
684+ nid' == nid
685+NodeIdentifier nid `impliesDeathOf` ProcessIdentifier pid =
686+ processNodeId pid == nid
687+NodeIdentifier nid `impliesDeathOf` SendPortIdentifier cid =
688+ processNodeId (sendPortProcessId cid) == nid
689+ProcessIdentifier pid `impliesDeathOf` ProcessIdentifier pid' =
690+ pid' == pid
691+ProcessIdentifier pid `impliesDeathOf` SendPortIdentifier cid =
692+ sendPortProcessId cid == pid
693+SendPortIdentifier cid `impliesDeathOf` SendPortIdentifier cid' =
694+ cid' == cid
695+_ `impliesDeathOf` _ =
696+ False