Skip to content

Commit

Permalink
peer-state-actions: Set the peer as warm before monitoring
Browse files Browse the repository at this point in the history
The peer status must be set to PeerWarm before we start the monitoring
thread.

Previously we started the monitoring thread first which meant that it
was possible for the monitor thread to notice an error and set the peer
status to PeerCold only to have it overwritten with PeerWarm. This
caused peers to get stuck in warm/hot without a corresponding
connection.
  • Loading branch information
karknu authored and coot committed Oct 14, 2021
1 parent 2256881 commit 0e0af25
Showing 1 changed file with 8 additions and 7 deletions.
Expand Up @@ -667,6 +667,14 @@ withPeerStateActions PeerStateActionsArguments {
awaitVarBundle
}

startProtocols TokWarm connHandle
startProtocols TokEstablished connHandle
atomically $ writeTVar peerStateVar (PeerStatus PeerWarm)
traceWith spsTracer (PeerStatusChanged
(ColdToWarm
(Just localAddress)
remoteAddress))

JobPool.forkJob jobPool
(Job (handleJust
(\e -> case fromException e of
Expand All @@ -679,13 +687,6 @@ withPeerStateActions PeerStateActionsArguments {
(return . Just)
()
("peerMonitoringLoop " ++ show remoteAddress))
startProtocols TokWarm connHandle
startProtocols TokEstablished connHandle
atomically $ writeTVar peerStateVar (PeerStatus PeerWarm)
traceWith spsTracer (PeerStatusChanged
(ColdToWarm
(Just localAddress)
remoteAddress))
pure connHandle

Disconnected _ Nothing ->
Expand Down

0 comments on commit 0e0af25

Please sign in to comment.