Skip to content

Commit

Permalink
Merge #85159
Browse files Browse the repository at this point in the history
85159: requestbatcher: nil unused slice entries in batchQueue heap r=nvanbenschoten a=nvanbenschoten

This change nils out unused entries in the `batchQueue`'s slice when the slice is truncated to avoid retaining references to batches of requests and preventing them from being GCed.

The change also removes a redundant update of the batchQueue's byRange map. The `delete` was redundant because `heap.Remove` already calls `Pop`.

I found this while looking at https://github.com/cockroachlabs/support/issues/1707, but I don't think this is actually the cause of the perceived memory leak.

Co-authored-by: Nathan VanBenschoten <[email protected]>
  • Loading branch information
craig[bot] and nvanbenschoten committed Aug 1, 2022
2 parents 5fe0527 + ac2185f commit 7dae9c4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/internal/client/requestbatcher/batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ func (q *batchQueue) get(id roachpb.RangeID) (*batch, bool) {
}

func (q *batchQueue) remove(ba *batch) {
delete(q.byRange, ba.rangeID())
heap.Remove(q, ba.idx)
}

Expand Down Expand Up @@ -678,6 +677,7 @@ func (q *batchQueue) Push(v interface{}) {

func (q *batchQueue) Pop() interface{} {
ba := q.batches[len(q.batches)-1]
q.batches[len(q.batches)-1] = nil // for GC
q.batches = q.batches[:len(q.batches)-1]
delete(q.byRange, ba.rangeID())
ba.idx = -1
Expand Down

0 comments on commit 7dae9c4

Please sign in to comment.