From bc21b0a8f5a0f79ae24cf044a3ab2ce896c72e1c Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Thu, 7 Jul 2022 17:20:39 -0700 Subject: [PATCH] row: only store the accounted for memory if the reservation is approved Previously, we would update the counter about the reserved memory before doing the reservation. If that reservation is denied, then later on, in `txnKVFetcher.close` we could try to release more memory than we registered. This is now fixed. Release note: None --- pkg/sql/row/kv_batch_fetcher.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/sql/row/kv_batch_fetcher.go b/pkg/sql/row/kv_batch_fetcher.go index 50312f026a5c..71b952b87739 100644 --- a/pkg/sql/row/kv_batch_fetcher.go +++ b/pkg/sql/row/kv_batch_fetcher.go @@ -356,10 +356,11 @@ func (f *txnKVFetcher) SetupNextFetch( // Account for the memory of the spans that we're taking the ownership of. if f.acc != nil { - f.spansAccountedFor = spans.MemUsage() - if err := f.acc.Grow(ctx, f.spansAccountedFor); err != nil { + newSpansAccountedFor := spans.MemUsage() + if err := f.acc.Grow(ctx, newSpansAccountedFor); err != nil { return err } + f.spansAccountedFor = newSpansAccountedFor } if spanIDs != nil && len(spans) != len(spanIDs) {