From 35dd07c4e045c41b74356dbb092988ebd28aab79 Mon Sep 17 00:00:00 2001 From: Ed Welch Date: Fri, 10 Jan 2020 08:08:57 -0500 Subject: [PATCH] fixes a panic where prefetch could try to operate on a nil object (#1499) Signed-off-by: Edward Welch --- pkg/storage/iterator.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/storage/iterator.go b/pkg/storage/iterator.go index 9cef67a8da790..808fece43eeba 100644 --- a/pkg/storage/iterator.go +++ b/pkg/storage/iterator.go @@ -118,6 +118,11 @@ func newBatchChunkIterator(ctx context.Context, chunks []*chunkenc.LazyChunk, ba select { case <-ctx.Done(): close(res.next) + // next can be nil if we are waiting to return that the nextBatch was empty and the context is closed + // or if another error occurred reading nextBatch + if next == nil { + return + } err = next.Close() if err != nil { level.Error(util.Logger).Log("msg", "Failed to close the pre-fetched iterator when pre-fetching was canceled", "err", err)