Skip to content

Commit

Permalink
storage: fix leaked iterators in unit tests
Browse files Browse the repository at this point in the history
Fix a couple instances of leaked iterators in unit tests in the storage
package.

This should also resolve the goroutine leak observed in cockroachdb#86256.

Informs cockroachdb#71481.

Release justification: Non-production code changes
Release note: None
  • Loading branch information
jbowens committed Aug 31, 2022
1 parent 634e4b4 commit 6afe5f8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/storage/mvcc_history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2301,7 +2301,8 @@ func metamorphicReader(e *evalCtx) (r Reader, closer func()) {
case "engine":
return e.engine, nil
case "readonly":
return e.engine.NewReadOnly(StandardDurability), nil
readOnly := e.engine.NewReadOnly(StandardDurability)
return readOnly, readOnly.Close
case "batch":
batch := e.engine.NewBatch()
return batch, batch.Close
Expand Down
1 change: 1 addition & 0 deletions pkg/storage/mvcc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5955,6 +5955,7 @@ func TestMVCCGarbageCollectClearRange(t *testing.T) {
LowerBound: rangeStart,
UpperBound: rangeEnd,
})
defer it.Close()
expMs, err := ComputeStatsForIter(it, tsMax.WallTime)
require.NoError(t, err, "failed to compute stats for range")
require.EqualValues(t, expMs, ms, "computed range stats vs gc'd")
Expand Down

0 comments on commit 6afe5f8

Please sign in to comment.