Skip to content

Commit 7adce5f

Browse files
committed
fix leak in block presence manager
1 parent 6cd1ed9 commit 7adce5f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

bitswap/client/internal/blockpresencemanager/blockpresencemanager.go

+4
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ func (bpm *BlockPresenceManager) allDontHave(peers []peer.ID, c cid.Cid) bool {
111111

112112
// RemoveKeys cleans up the given keys from the block presence map
113113
func (bpm *BlockPresenceManager) RemoveKeys(ks []cid.Cid) {
114+
if len(ks) == 0 {
115+
return
116+
}
117+
114118
bpm.Lock()
115119
defer bpm.Unlock()
116120

bitswap/client/internal/session/session.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ type Session struct {
111111
sprm SessionPeerManager
112112
providerFinder ProviderFinder
113113
sim *bssim.SessionInterestManager
114+
bpm *bsbpm.BlockPresenceManager
114115

115116
sw sessionWants
116117
sws sessionWantSender
@@ -162,6 +163,7 @@ func New(
162163
sprm: sprm,
163164
providerFinder: providerFinder,
164165
sim: sim,
166+
bpm: bpm,
165167
incoming: make(chan op, 128),
166168
latencyTrkr: latencyTracker{},
167169
notif: notif,
@@ -443,7 +445,10 @@ func (s *Session) handleReceive(ks []cid.Cid) {
443445

444446
// Inform the SessionInterestManager that this session is no longer
445447
// expecting to receive the wanted keys
446-
s.sim.RemoveSessionInterested(s.id, wanted)
448+
deleted := s.sim.RemoveSessionInterested(s.id, wanted)
449+
// make sure to clean up the block presence manager
450+
// for keys no session is interested in
451+
s.bpm.RemoveKeys(deleted)
447452

448453
s.idleTick.Stop()
449454

0 commit comments

Comments
 (0)