{"record":{"id":"b22e1c93db9782fa","repo":"thanos-io/thanos","slug":"reading-postings","errorCode":null,"errorMessage":"reading postings","messagePattern":"reading postings","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/bucket.go","lineNumber":3248,"sourceCode":"\t\t\t\tdataToCache, err := snappyStreamedEncode(int(postingsCount), diffVarintPostings)\n\t\t\t\tif err != nil {\n\t\t\t\t\tstats.cachedPostingsCompressionErrors += 1\n\t\t\t\t\treturn errors.Wrap(err, \"encoding with snappy\")\n\t\t\t\t}\n\n\t\t\t\tstats.cachedPostingsCompressions += 1\n\t\t\t\tstats.CachedPostingsOriginalSizeSum += units.Base2Bytes(len(diffVarintPostings))\n\t\t\t\tstats.CachedPostingsCompressedSizeSum += units.Base2Bytes(len(dataToCache))\n\t\t\t\tstats.CachedPostingsCompressionTimeSum += time.Since(startCompression)\n\t\t\t\tstats.add(PostingsTouched, 1, len(diffVarintPostings))\n\n\t\t\t\tr.block.indexCache.StorePostings(r.block.meta.ULID, keys[keyID], dataToCache, tenant)\n\t\t\t}\n\n\t\t\tstats.PostingsFetchDurationSum += time.Since(begin)\n\n\t\t\tif err := rdr.Error(); err != nil {\n\t\t\t\treturn errors.Wrap(err, \"reading postings\")\n\t\t\t}\n\t\t\treturn nil\n\t\t})\n\t}\n\n\treturn output, closeFns, g.Wait()\n}\n\nfunc (r *bucketIndexReader) decodeCachedPostings(b []byte) (index.Postings, []func(), error) {\n\t// Even if this instance is not using compression, there may be compressed\n\t// entries in the cache written by other stores.\n\tvar (\n\t\tl        index.Postings\n\t\terr      error\n\t\tcloseFns []func()\n\t)\n\tif isDiffVarintSnappyEncodedPostings(b) || isDiffVarintSnappyStreamedEncodedPostings(b) {\n\t\ts := time.Now()","sourceCodeStart":3230,"sourceCodeEnd":3266,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/bucket.go#L3230-L3266","documentation":"After streaming the postings range through the postings reader (newPostingsReaderBuilder over a bufio.Reader), rdr.Error() reports any error accumulated while parsing the postings stream. This error means the ranged bytes from the index were read (or the underlying object-storage stream errored) but could not be fully parsed into postings.","triggerScenarios":"The object-storage range reader returned an error mid-stream (connection reset, context cancellation, timeout), or the postings binary data in the index range is corrupt/truncated so the diff-varint decoding fails while rdr iterates over ptrs[i:j].","commonSituations":"Unstable connection to S3/GCS causing mid-body stream failures; context canceled by client query timeout/cancellation; corrupted or partially uploaded index block; block replaced in the bucket while being read.","solutions":["Retry the query; transient stream errors are the most common cause","Check query/store-gateway logs for context cancellation and increase query timeouts if applicable","Validate the block (thanos tools bucket verify) — re-upload or delete the block if the index is corrupted","Ensure the block is not modified/deleted while readers are using it (use deletion marks and proper block lifecycle)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"select {\ncase <-ctx.Done():\n\t// abort before streaming: context already canceled\n\treturn ctx.Err()\ndefault:\n}","typeGuard":"func isStreamErr(err error) bool { return errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) }","tryCatchPattern":"if err := rdr.Error(); err != nil {\n\tif isStreamErr(err) {\n\t\treturn retry.WithBackoff(ctx, func() error { return fetchPostingsRange(ctx, ptrs) })\n\t}\n\treturn errors.Wrap(err, \"reading postings\")\n}","preventionTips":["Set query timeouts comfortably above object-storage latencies","Use stable network paths/VPC endpoints to the bucket","Verify blocks before serving after failed uploads","Retry idempotent ranged reads on transient stream errors"],"tags":["thanos","index","streaming","object-storage","decoding"],"backgroundTag":"network-request-failed","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}