Skip to content

Commit 9e257a7

Browse files
authored
Always send cancels even if peer has no interest (#829)
* Always send cancels even if peer has no interest * increase max send delay
1 parent 49f6c15 commit 9e257a7

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ The following emojis are used to highlight certain changes:
2222

2323
### Fixed
2424

25+
- Fix memory leak due to not cleaning up wantlists [#829](https://github.com/ipfs/boxo/pull/829)
26+
2527
### Security
2628

2729

bitswap/client/internal/messagequeue/messagequeue.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const (
4444
sendTimeout = 30 * time.Second
4545

4646
defaultPerPeerDelay = time.Millisecond / 8
47-
maxSendMessageDelay = time.Second
47+
maxSendMessageDelay = 2 * time.Second
4848
minSendMessageDelay = 20 * time.Millisecond
4949
)
5050

bitswap/client/internal/sessionmanager/sessionmanager.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ func (sm *SessionManager) GetNextSessionID() uint64 {
157157
// their contents. If the caller needs to preserve a copy of the lists it
158158
// should make a copy before calling ReceiveFrom.
159159
func (sm *SessionManager) ReceiveFrom(ctx context.Context, p peer.ID, blks []cid.Cid, haves []cid.Cid, dontHaves []cid.Cid) {
160+
// Send CANCEL to all peers with want-have / want-block. This needs to be
161+
// done before filtering out CIDs that peers are no longer interested in,
162+
// to ensure they are removed from PeerManager and PeerQueue want lists.
163+
sm.peerManager.SendCancels(ctx, blks)
164+
160165
// Keep only the keys that at least one session wants
161166
keys := sm.sessionInterestManager.FilterInterests(blks, haves, dontHaves)
162167
blks = keys[0]
@@ -179,9 +184,6 @@ func (sm *SessionManager) ReceiveFrom(ctx context.Context, p peer.ID, blks []cid
179184
sess.ReceiveFrom(p, blks, haves, dontHaves)
180185
}
181186
}
182-
183-
// Send CANCEL to all peers with want-have / want-block
184-
sm.peerManager.SendCancels(ctx, blks)
185187
}
186188

187189
// CancelSessionWants is called when a session cancels wants because a call to

0 commit comments

Comments
 (0)