Skip to content

Commit

Permalink
Merge #66106
Browse files Browse the repository at this point in the history
66106: colcontainer: fix intra-query memory leak r=jordanlewis a=jordanlewis

Closes #66107.

Previously, when closing a diskQueue (the structure that's used to
implement disk spilling), we failed to properly allow all scratch memory
to be reclaimed by the garbage collector.

Release note (sql change): prevent intra-query leak during disk spilling
that could cause the database to run out of memory, especially during
disk spilling operations on tables with wide rows.

Co-authored-by: Jordan Lewis <[email protected]>
  • Loading branch information
craig[bot] and jordanlewis committed Jun 5, 2021
2 parents 9cef2e9 + 6a52de4 commit 9a1a5eb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/sql/colcontainer/diskqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,13 @@ func (d *diskQueue) closeFileDeserializer() error {
}

func (d *diskQueue) Close(ctx context.Context) error {
defer func() {
// Zero out the structure completely upon return. If users of this diskQueue
// retain a pointer to it, and we don't remove all references to large
// backing slices (various scratch spaces in this struct and children),
// we'll be "leaking memory" until users remove their references.
*d = diskQueue{}
}()
if d.serializer != nil {
if err := d.writeFooterAndFlush(ctx); err != nil {
return err
Expand Down

0 comments on commit 9a1a5eb

Please sign in to comment.