Skip to content

Commit

Permalink
release priority locks early when handling batches
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Jul 16, 2021
1 parent 97f35c4 commit e1ea949
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,15 @@ func (p *PubSub) processLoop(ctx context.Context) {

func (p *PubSub) handlePendingPeers() {
p.newPeersPrioLk.Lock()
defer p.newPeersPrioLk.Unlock()

if len(p.newPeersPend) == 0 {
p.newPeersPrioLk.Unlock()
return
}

newPeers := p.newPeersPend
p.newPeersPend = make(map[peer.ID]struct{})
p.newPeersPrioLk.Unlock()

for pid := range newPeers {
if p.host.Network().Connectedness(pid) != network.Connected {
Expand All @@ -632,14 +633,15 @@ func (p *PubSub) handlePendingPeers() {

func (p *PubSub) handleDeadPeers() {
p.peerDeadPrioLk.Lock()
defer p.peerDeadPrioLk.Unlock()

if len(p.peerDeadPend) == 0 {
p.peerDeadPrioLk.Unlock()
return
}

deadPeers := p.peerDeadPend
p.peerDeadPend = make(map[peer.ID]struct{})
p.peerDeadPrioLk.Unlock()

for pid := range deadPeers {
ch, ok := p.peers[pid]
Expand Down

0 comments on commit e1ea949

Please sign in to comment.