Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
fix: ensure wantlist gauge gets decremented on disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc committed Apr 3, 2020
1 parent d39c760 commit d310fe3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/peermanager/peerwantmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ func (pwm *peerWantManager) addPeer(p peer.ID) {

// RemovePeer removes a peer and its associated wants from tracking
func (pwm *peerWantManager) removePeer(p peer.ID) {
pws, ok := pwm.peerWants[p]
if !ok {
return
}

// Decrement the gauge by the number of pending want-blocks to the peer
for range pws.wantBlocks.Keys() {
pwm.wantBlockGauge.Dec()
}

delete(pwm.peerWants, p)
}

Expand Down
6 changes: 6 additions & 0 deletions internal/peermanager/peerwantmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,10 @@ func TestStats(t *testing.T) {
if g.count != 3 {
t.Fatal("Expected 3 want-blocks", g.count)
}

pwm.removePeer(p0)

if g.count != 0 {
t.Fatal("Expected all want-blocks to be removed with peer", g.count)
}
}

0 comments on commit d310fe3

Please sign in to comment.