fix: reset peer backoff on recovery so reconnect is not blocked (#1308)

Signed-off-by: kblinichkin <kirill.blinichkin@gmail.com>
This commit is contained in:
Kirill Blinichkin 2026-06-15 06:44:59 -05:00 committed by GitHub
parent 2ccee74ecb
commit 81291ef862
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View File

@ -90,11 +90,13 @@ func (w *WakuNode) startKeepAlive(ctx context.Context, randomPeersPingDuration t
lastTimeExecuted = w.timesource.Now()
w.log.Warn("keep alive hasnt been executed recently. Killing all connections")
disconnectAllPeers(w.host, w.log)
w.peerConnector.ResetBackoff()
continue
} else if iterationFailure >= maxAllowedSubsequentPingFailures {
iterationFailure = 0
w.log.Warn("Pinging random peers failed, node is likely disconnected. Killing all connections")
disconnectAllPeers(w.host, w.log)
w.peerConnector.ResetBackoff()
continue
}

View File

@ -218,6 +218,16 @@ func (c *PeerConnectionStrategy) canDialPeer(pi peer.AddrInfo) bool {
return true
}
// ResetBackoff clears all accumulated per-peer connection backoffs so that
// every known peer can be retried immediately on the next connection attempt.
// Call this after a recovery event (e.g. sleep/wake, all pings failed) so that
// stale hour-long backoffs do not prevent reconnection once the network is back.
func (c *PeerConnectionStrategy) ResetBackoff() {
c.mux.Lock()
defer c.mux.Unlock()
c.cache.Purge()
}
func (c *PeerConnectionStrategy) addConnectionBackoff(peerID peer.ID) {
c.mux.Lock()
defer c.mux.Unlock()