{"record":{"id":"1b18b0fda74b4e0a","repo":"thanos-io/thanos","slug":"reading","errorCode":null,"errorMessage":"reading","messagePattern":"reading","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/postings.go","lineNumber":54,"sourceCode":"// and builds a diff varint encoded []byte that could be later used directly.\nfunc newPostingsReaderBuilder(ctx context.Context, r *bufio.Reader, postings []postingPtr, start, length int64) *postingsReaderBuilder {\n\tprb := &postingsReaderBuilder{\n\t\tr:                r,\n\t\treadBuf:          make([]byte, 4),\n\t\tstart:            start,\n\t\tlength:           length,\n\t\tpostings:         postings,\n\t\tuvarintEncodeBuf: make([]byte, binary.MaxVarintLen64),\n\t\tctx:              ctx,\n\t}\n\n\treturn prb\n}\n\nfunc getInt32(r io.Reader, buf []byte) (uint32, error) {\n\tread, err := io.ReadFull(r, buf)\n\tif err != nil {\n\t\treturn 0, errors.Wrap(err, \"reading\")\n\t}\n\tif read != 4 {\n\t\treturn 0, fmt.Errorf(\"read got %d bytes instead of 4\", read)\n\t}\n\treturn binary.BigEndian.Uint32(buf), nil\n}\n\nfunc (r *postingsReaderBuilder) Next() bool {\n\tif r.ctx.Err() != nil {\n\t\tr.e = r.ctx.Err()\n\t\treturn false\n\t}\n\tif r.repeatFor > 0 {\n\t\tr.keyID = r.postings[r.pi-r.repeatFor].keyID\n\t\tr.repeatFor--\n\t\treturn true\n\t}\n\tif r.pi >= len(r.postings) {","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/postings.go#L36-L72","documentation":"getInt32 reads exactly 4 bytes from an index postings reader; io.ReadFull failures (EOF, closed reader) are wrapped as \"reading\". It signals the postings binary stream ended prematurely or the underlying reader broke while decoding a posting count.","triggerScenarios":"postingsReaderBuilder.Next reading from a truncated/corrupted postings file, a closed connection/stream, or an EOF at the end of malformed data.","commonSituations":"Corrupted block index files in object storage; interrupted downloads leaving partial index data; reading a buffer/stream that was closed early.","solutions":["Re-download/repair the block index (delete the cached partial file and re-sync).","Verify block integrity with thanos tools bucket verify.","Check that the underlying reader/stream is not closed while reading.","Inspect the wrapped error (io.EOF vs io.ErrUnexpectedEOF vs syscall errors) for the exact cause."],"exampleFix":"// before\n// reuse of possibly corrupt cached index\n// after\nos.Remove(cacheIndexFile) // force re-download and re-verify checksum\nstore.SyncBlocks(ctx)","handlingStrategy":"fallback","validationCode":"// validate index integrity before decoding\nif err := verifyIndexChecksum(indexPath); err != nil { reDownloadIndex() }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"reading\") {\n  if errors.Is(errors.Unwrap(err), io.EOF) || errors.Is(errors.Unwrap(err), io.ErrUnexpectedEOF) {\n    // treat as corrupt/truncated index: re-fetch block\n  }\n}","preventionTips":["Verify block checksums after download (bucket verify)","Delete partial caches on failed downloads","Alert on index-corruption metrics from store-gateway"],"tags":["go","io","index","corruption"],"backgroundTag":"file-read-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"}