Skip to content

Commit

Permalink
fix handling of dead peers (libp2p#492)
Browse files Browse the repository at this point in the history
* fix handling of dead peers

* remove unnecessary continue
  • Loading branch information
vyzo authored Jul 1, 2022
1 parent 96efa27 commit 60cf380
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}

Expand Down

0 comments on commit 60cf380

Please sign in to comment.