Skip to content

Commit

Permalink
Unregister cold connections, even in case of errors
Browse files Browse the repository at this point in the history
When marking a peer as cold make sure to call
unregisterOutboundConnection. Previously connections could be left in
the connection manager without a corresponding hot or warm peer and
without a snocket.
  • Loading branch information
karknu authored and coot committed Oct 14, 2021
1 parent e8d4d2d commit 606833a
Showing 1 changed file with 5 additions and 0 deletions.
Expand Up @@ -608,13 +608,16 @@ withPeerStateActions PeerStateActionsArguments {
--
WithSomeProtocolTemperature (WithHot MiniProtocolError{}) -> do
traceWith spsTracer (PeerStatusChanged (HotToCold pchConnectionId))
_ <- unregisterOutboundConnection spsConnectionManager (remoteAddress pchConnectionId)
atomically (writeTVar pchPeerState (PeerStatus PeerCold))
WithSomeProtocolTemperature (WithWarm MiniProtocolError{}) -> do
traceWith spsTracer (PeerStatusChanged (WarmToCold pchConnectionId))
_ <- unregisterOutboundConnection spsConnectionManager (remoteAddress pchConnectionId)
atomically (writeTVar pchPeerState (PeerStatus PeerCold))
WithSomeProtocolTemperature (WithEstablished MiniProtocolError{}) -> do
-- update 'pchPeerState' and log (as the two other transition to
-- cold state.
_ <- unregisterOutboundConnection spsConnectionManager (remoteAddress pchConnectionId)
state <- atomically $ do
peerState <- readTVar pchPeerState
writeTVar pchPeerState (PeerStatus PeerCold)
Expand Down Expand Up @@ -839,13 +842,15 @@ withPeerStateActions PeerStateActionsArguments {
case res of
Nothing -> do
Mux.stopMux pchMux
_ <- unregisterOutboundConnection spsConnectionManager (remoteAddress pchConnectionId)
atomically (writeTVar pchPeerState (PeerStatus PeerCold))
traceWith spsTracer (PeerStatusChangeFailure
(HotToWarm pchConnectionId)
TimeoutError)
throwIO (DeactivationTimeout pchConnectionId)

Just (SomeErrored errs) -> do
_ <- unregisterOutboundConnection spsConnectionManager (remoteAddress pchConnectionId)
atomically (writeTVar pchPeerState (PeerStatus PeerCold))
traceWith spsTracer (PeerStatusChangeFailure
(HotToCold pchConnectionId)
Expand Down

0 comments on commit 606833a

Please sign in to comment.