Skip to content

Commit 6c9f559

Browse files
authored
Merge pull request ipfs/go-bitswap#332 from ipfs/fix/wantlist-gauge
fix: ensure wantlist gauge gets decremented on disconnect This commit was moved from ipfs/go-bitswap@53af318
2 parents 41b924e + d18c4c0 commit 6c9f559

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

bitswap/internal/peermanager/peerwantmanager.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ func (pwm *peerWantManager) addPeer(p peer.ID) {
5050

5151
// RemovePeer removes a peer and its associated wants from tracking
5252
func (pwm *peerWantManager) removePeer(p peer.ID) {
53+
pws, ok := pwm.peerWants[p]
54+
if !ok {
55+
return
56+
}
57+
58+
// Decrement the gauge by the number of pending want-blocks to the peer
59+
for range pws.wantBlocks.Keys() {
60+
pwm.wantBlockGauge.Dec()
61+
}
62+
5363
delete(pwm.peerWants, p)
5464
}
5565

bitswap/internal/peermanager/peerwantmanager_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,4 +289,10 @@ func TestStats(t *testing.T) {
289289
if g.count != 3 {
290290
t.Fatal("Expected 3 want-blocks", g.count)
291291
}
292+
293+
pwm.removePeer(p0)
294+
295+
if g.count != 0 {
296+
t.Fatal("Expected all want-blocks to be removed with peer", g.count)
297+
}
292298
}

0 commit comments

Comments
 (0)