diff --git a/pubsub.go b/pubsub.go index eca29af1..e44c7f1c 100644 --- a/pubsub.go +++ b/pubsub.go @@ -696,6 +696,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) @@ -709,20 +719,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) } }