diff --git a/pkg/store/bucket.go b/pkg/store/bucket.go index f5b71b434ab..780a2013aa4 100644 --- a/pkg/store/bucket.go +++ b/pkg/store/bucket.go @@ -2864,14 +2864,13 @@ func (r *bucketIndexReader) decodeCachedPostings(b []byte) (index.Postings, []fu ) if isDiffVarintSnappyEncodedPostings(b) || isDiffVarintSnappyStreamedEncodedPostings(b) { s := time.Now() - clPostings, err := decodePostings(b) + l, err = decodePostings(b) r.stats.cachedPostingsDecompressions += 1 r.stats.CachedPostingsDecompressionTimeSum += time.Since(s) if err != nil { r.stats.cachedPostingsDecompressionErrors += 1 } else { - closeFns = append(closeFns, clPostings.close) - l = clPostings + closeFns = append(closeFns, l.(closeablePostings).close) } } else { _, l, err = r.dec.Postings(b) diff --git a/pkg/store/bucket_test.go b/pkg/store/bucket_test.go index 0d40f18bc37..31c25d776ab 100644 --- a/pkg/store/bucket_test.go +++ b/pkg/store/bucket_test.go @@ -3330,3 +3330,16 @@ func TestExpandedPostingsRace(t *testing.T) { wg.Wait() } } + +func TestBucketIndexReader_decodeCachedPostingsErrors(t *testing.T) { + bir := bucketIndexReader{stats: &queryStats{}} + t.Run("should return error on broken cached postings without snappy prefix", func(t *testing.T) { + _, _, err := bir.decodeCachedPostings([]byte("foo")) + testutil.NotOk(t, err) + }) + t.Run("should return error on broken cached postings with snappy prefix", func(t *testing.T) { + _, _, err := bir.decodeCachedPostings(append([]byte(codecHeaderSnappy), []byte("foo")...)) + testutil.NotOk(t, err) + }) + +}