@@ -737,22 +737,24 @@ handleIncomingMessages (ourEndPoint, theirEndPoint) = do
737737
738738 -- Normally, there would be no unclosed connections, but if the client
739739 -- exits prematurely there might be
740− unclosedConnections <- modifyMVar theirState $ \st ->
740+ mUnclosedConnections <- modifyMVar theirState $ \st ->
741741 case st of
742742 RemoteEndPointInvalid _ ->
743743 error "handleIncomingMessages RELY violation"
744744 RemoteEndPointValid remoteConn ->
745− return (RemoteEndPointValid . (remoteIncoming ^= IntSet.empty) $ remoteConn, remoteConn ^. remoteIncoming)
746− RemoteEndPointClosing resolved remoteConn ->
747− return (RemoteEndPointClosing resolved . (remoteIncoming ^= IntSet.empty) $ remoteConn, remoteConn ^. remoteIncoming)
745+ return (RemoteEndPointClosed, Just $ remoteConn ^. remoteIncoming)
746+ RemoteEndPointClosing _ _ ->
747+ return (RemoteEndPointClosed, Nothing)
748748 RemoteEndPointClosed ->
749− return (st, IntSet.empty)
749+ return (st, Nothing)
750750
751− -- TODO: should we give a single ErrorEvent instead?
752− forM_ (map fromIntegral $ IntSet.elems unclosedConnections) $ \cid -> do
753− writeChan ourChannel $ ConnectionClosed cid
751+ -- TODO: we need to remote this endpoint from localConnections at this point
752+
753+ case mUnclosedConnections of
754+ Nothing -> return ()
755+ Just unclosedConnections ->
756+ writeChan ourChannel (ErrorEvent EventErrorEndPointClosed (IntSet.elems unclosedConnections))
754757
755− -- TODO: if the endpoint was not in closing state, should we make it so?
756758 where
757759 -- Dispatch
758760 go :: N.Socket -> IO ()
@@ -787,7 +789,7 @@ handleIncomingMessages (ourEndPoint, theirEndPoint) = do
787789 modifyMVar_ theirState $ \st -> do
788790 remoteConn <- case st of
789791 RemoteEndPointValid remoteConn ->
790− return (remoteIncoming ^%= IntSet.insert (fromIntegral newId) $ remoteConn)
792+ return (remoteIncoming ^%= IntSet.insert newId $ remoteConn)
791793 RemoteEndPointClosing resolved remoteConn -> do
792794 -- If the endpoint is in closing state that means we send a
793795 -- CloseSocket request to the remote endpoint. If the remote