git.iko.soy/distributed-process
on master help sign in
Continue work on improved error handling
62133a7Edsko de Vries
network-transport-2/src/Network/Transport/TCP.hs+12−10
@@ -737,22 +737,24 @@ handleIncomingMessages (ourEndPoint, theirEndPoint) = do
737
737
738 -- Normally, there would be no unclosed connections, but if the client
738 -- Normally, there would be no unclosed connections, but if the client
739 -- exits prematurely there might be
739 -- exits prematurely there might be
740− unclosedConnections <- modifyMVar theirState $ \st ->
740+ mUnclosedConnections <- modifyMVar theirState $ \st ->
741 case st of
741 case st of
742 RemoteEndPointInvalid _ ->
742 RemoteEndPointInvalid _ ->
743 error "handleIncomingMessages RELY violation"
743 error "handleIncomingMessages RELY violation"
744 RemoteEndPointValid remoteConn ->
744 RemoteEndPointValid remoteConn ->
745− return (RemoteEndPointValid . (remoteIncoming ^= IntSet.empty) $ remoteConn, remoteConn ^. remoteIncoming)
745+ return (RemoteEndPointClosed, Just $ remoteConn ^. remoteIncoming)
746− RemoteEndPointClosing resolved remoteConn ->
746+ RemoteEndPointClosing _ _ ->
747− return (RemoteEndPointClosing resolved . (remoteIncoming ^= IntSet.empty) $ remoteConn, remoteConn ^. remoteIncoming)
747+ return (RemoteEndPointClosed, Nothing)
748 RemoteEndPointClosed ->
748 RemoteEndPointClosed ->
749− return (st, IntSet.empty)
749+ return (st, Nothing)
750
750
751− -- TODO: should we give a single ErrorEvent instead?
751+ -- TODO: we need to remote this endpoint from localConnections at this point
752+
753+ case mUnclosedConnections of
754+ Nothing -> return ()
755+ Just unclosedConnections ->
752− forM_ (map fromIntegral $ IntSet.elems unclosedConnections) $ \cid -> do
756+ writeChan ourChannel (ErrorEvent EventErrorEndPointClosed (IntSet.elems unclosedConnections))
753− writeChan ourChannel $ ConnectionClosed cid
754
757
755− -- TODO: if the endpoint was not in closing state, should we make it so?
756 where
758 where
757 -- Dispatch
759 -- Dispatch
758 go :: N.Socket -> IO ()
760 go :: N.Socket -> IO ()
@@ -787,7 +789,7 @@ handleIncomingMessages (ourEndPoint, theirEndPoint) = do
787 modifyMVar_ theirState $ \st -> do
789 modifyMVar_ theirState $ \st -> do
788 remoteConn <- case st of
790 remoteConn <- case st of
789 RemoteEndPointValid remoteConn ->
791 RemoteEndPointValid remoteConn ->
790− return (remoteIncoming ^%= IntSet.insert (fromIntegral newId) $ remoteConn)
792+ return (remoteIncoming ^%= IntSet.insert newId $ remoteConn)
791 RemoteEndPointClosing resolved remoteConn -> do
793 RemoteEndPointClosing resolved remoteConn -> do
792 -- If the endpoint is in closing state that means we send a
794 -- If the endpoint is in closing state that means we send a
793 -- CloseSocket request to the remote endpoint. If the remote
795 -- CloseSocket request to the remote endpoint. If the remote