{"record":{"id":"6218adaedc56a26f","repo":"thanos-io/thanos","slug":"mismatched-checksum-got-v-expected-v","errorCode":null,"errorMessage":"mismatched checksum (got %v, expected %v)","messagePattern":"mismatched checksum \\(got (.+?), expected (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/store/postings_codec.go","lineNumber":306,"sourceCode":"\t\t\t}\n\t\t}\n\n\t\tencodedBuf := it.input[:chunkLen]\n\n\t\t// NOTE(GiedriusS): we can probably optimize this better but this should be rare enough\n\t\t// and not cause any problems.\n\t\tif len(remainder) > 0 {\n\t\t\tremainderCopy := make([]byte, 0, len(remainder))\n\t\t\tremainderCopy = append(remainderCopy, remainder...)\n\t\t\tremainder = remainderCopy\n\t\t}\n\t\tdecoded, err := s2.Decode(it.buf, encodedBuf[checksumSize:])\n\t\tif err != nil {\n\t\t\tit.err = err\n\t\t\treturn false\n\t\t}\n\t\tif crc(decoded) != checksum {\n\t\t\tit.err = fmt.Errorf(\"mismatched checksum (got %v, expected %v)\", crc(decoded), checksum)\n\t\t\treturn false\n\t\t}\n\t\tif len(remainder) > 0 {\n\t\t\tit.db.B = append(remainder, decoded...)\n\t\t} else {\n\t\t\tit.db.B = decoded\n\t\t}\n\tcase chunkTypeUncompressedData:\n\t\tif !it.readSnappyIdentifier {\n\t\t\tit.err = fmt.Errorf(\"missing magic snappy marker\")\n\t\t\treturn false\n\t\t}\n\t\tif len(it.input) < 4 {\n\t\t\tit.err = io.ErrUnexpectedEOF\n\t\t\treturn false\n\t\t}\n\t\tchecksum := uint32(it.input[0]) | uint32(it.input[1])<<8 | uint32(it.input[2])<<16 | uint32(it.input[3])<<24\n\t\tif len(it.input) < chunkLen {","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/postings_codec.go#L288-L324","documentation":"After s2.Decode decompressed a chunkTypeCompressedData chunk, the CRC32 checksum of the decoded bytes did not match the checksum stored in the chunk header. This detects data corruption introduced either before compression (writer bug/bit rot) or after decompression (memory corruption), so the iterator aborts instead of returning wrong postings.","triggerScenarios":"Next() reads a compressed chunk whose stored checksum disagrees with crc32 of the s2-decompressed output — typically corrupted bytes on disk, a bad network transfer, or mismatched checksum function/endianness between writer and reader versions.","commonSituations":"Failing disk/SSD sectors in a TSDB block, interrupted block copy or rsync, downloading blocks over an unreliable link without verification, or tampered/incorrectly merged block files.","solutions":["Restore the block from a healthy replica or backup; this indicates real data corruption.","Run `promtool tsdb analyze` / `promtool check blocks` on the block directory to confirm and locate corruption.","Re-download the block (e.g. via Thanos/Cortex bucket re-sync) and verify checksums in transit.","Check storage hardware (SMART status) and disable any intermediary that rewrites bytes (compression proxies, FTP ASCII mode)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify block-level checksums before decoding\nfunc blockChecksumOk(meta BlockMeta, sum uint32) bool { return meta.CRC == sum }","typeGuard":null,"tryCatchPattern":"it := NewPostingsIterator(blob)\nif !it.Next() {\n    if err := it.Err(); err != nil {\n        var expected uint32\n        if errors.Is(err, ErrMismatchedChecksum) || strings.Contains(err.Error(), \"mismatched checksum\") {\n            // treat block as corrupt: fail over to replica\n        }\n    }\n}","preventionTips":["Verify file/object checksums after every block transfer.","Monitor disk health (SMART) on TSDB storage volumes.","Keep replicas so corrupted blocks can be replaced.","Avoid tools that rewrite block files without recomputing CRCs."],"tags":["go","snappy","postings","checksum","corruption"],"backgroundTag":"checksum-mismatch","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"}