Skip to content

Commit

Permalink
fix leak in block presence manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan committed Nov 18, 2024
1 parent 6cd1ed9 commit 7adce5f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func (bpm *BlockPresenceManager) allDontHave(peers []peer.ID, c cid.Cid) bool {

// RemoveKeys cleans up the given keys from the block presence map
func (bpm *BlockPresenceManager) RemoveKeys(ks []cid.Cid) {
if len(ks) == 0 {
return
}

bpm.Lock()
defer bpm.Unlock()

Expand Down
7 changes: 6 additions & 1 deletion bitswap/client/internal/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type Session struct {
sprm SessionPeerManager
providerFinder ProviderFinder
sim *bssim.SessionInterestManager
bpm *bsbpm.BlockPresenceManager

sw sessionWants
sws sessionWantSender
Expand Down Expand Up @@ -162,6 +163,7 @@ func New(
sprm: sprm,
providerFinder: providerFinder,
sim: sim,
bpm: bpm,
incoming: make(chan op, 128),
latencyTrkr: latencyTracker{},
notif: notif,
Expand Down Expand Up @@ -443,7 +445,10 @@ func (s *Session) handleReceive(ks []cid.Cid) {

// Inform the SessionInterestManager that this session is no longer
// expecting to receive the wanted keys
s.sim.RemoveSessionInterested(s.id, wanted)
deleted := s.sim.RemoveSessionInterested(s.id, wanted)
// make sure to clean up the block presence manager
// for keys no session is interested in
s.bpm.RemoveKeys(deleted)

s.idleTick.Stop()

Expand Down

1 comment on commit 7adce5f

@RobQuistNL
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3 awesome stuff

Please sign in to comment.