From 72562e61e1999afe21cd67d5e1f9fedfb3016024 Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 1 Jul 2022 19:37:38 +0300 Subject: [PATCH] fix handling of dead peers (#492) * fix handling of dead peers * remove unnecessary continue --- pubsub.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/pubsub.go b/pubsub.go index 98ebb34b..85df995e 100644 --- a/pubsub.go +++ b/pubsub.go @@ -695,6 +695,16 @@ func (p *PubSub) handleDeadPeers() { } close(ch) + delete(p.peers, pid) + + for t, tmap := range p.topics { + if _, ok := tmap[pid]; ok { + delete(tmap, pid) + p.notifyLeave(t, pid) + } + } + + p.rt.RemovePeer(pid) if p.host.Network().Connectedness(pid) == network.Connected { backoffDelay, err := p.deadPeerBackoff.updateAndGet(pid) @@ -708,20 +718,9 @@ func (p *PubSub) handleDeadPeers() { log.Debugf("peer declared dead but still connected; respawning writer: %s", pid) messages := make(chan *RPC, p.peerOutboundQueueSize) messages <- p.getHelloPacket() - go p.handleNewPeerWithBackoff(p.ctx, pid, backoffDelay, messages) p.peers[pid] = messages - continue - } - - delete(p.peers, pid) - for t, tmap := range p.topics { - if _, ok := tmap[pid]; ok { - delete(tmap, pid) - p.notifyLeave(t, pid) - } + go p.handleNewPeerWithBackoff(p.ctx, pid, backoffDelay, messages) } - - p.rt.RemovePeer(pid) } }