{"record":{"id":"3bd9c3f5f4afb97d","repo":"thanos-io/thanos","slug":"reading-chunk-length-failed","errorCode":null,"errorMessage":"reading chunk length failed","messagePattern":"reading chunk length failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/bucket.go","lineNumber":3790,"sourceCode":"\t\t// However, declaration for EstimatedMaxChunkSize warns us some chunks could be larger in some rare cases.\n\t\t// This is handled further down below.\n\t\tchunkLen = r.block.estimatedMaxChunkSize\n\t\tif i+1 < len(pIdxs) {\n\t\t\tif diff = pIdxs[i+1].offset - pIdx.offset; int(diff) < chunkLen {\n\t\t\t\tchunkLen = int(diff)\n\t\t\t}\n\t\t}\n\t\tcb := buf[:chunkLen]\n\t\tn, err = io.ReadFull(bufReader, cb)\n\t\treadOffset += n\n\t\t// Unexpected EOF for last chunk could be a valid case. Any other errors are definitely real.\n\t\tif err != nil && !errors.Is(err, io.ErrUnexpectedEOF) && i != len(pIdxs)-1 {\n\t\t\treturn errors.Wrapf(err, \"read range for seq %d offset %x\", seq, pIdx.offset)\n\t\t}\n\n\t\tchunkDataLen, n := binary.Uvarint(cb)\n\t\tif n < 1 {\n\t\t\treturn errors.New(\"reading chunk length failed\")\n\t\t}\n\n\t\t// Chunk length is n (number of bytes used to encode chunk data), 1 for chunk encoding and chunkDataLen for actual chunk data.\n\t\t// There is also crc32 after the chunk, but we ignore that.\n\t\tchunkLen = n + 1 + int(chunkDataLen)\n\t\tif chunkLen <= len(cb) {\n\t\t\tc := rawChunk(cb[n:chunkLen])\n\t\t\terr = populateChunk(&(res[pIdx.seriesEntry].chks[pIdx.chunk]), &c, aggrs, r.save, calculateChunkChecksum)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrap(err, \"populate chunk\")\n\t\t\t}\n\t\t\tstats.add(ChunksTouched, 1, int(chunkDataLen))\n\t\t\tcontinue\n\t\t}\n\n\t\tr.block.metrics.chunkRefetches.WithLabelValues(tenant).Inc()\n\t\t// If we didn't fetch enough data for the chunk, fetch more.\n\t\tfetchBegin = time.Now()","sourceCodeStart":3772,"sourceCodeEnd":3808,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/bucket.go#L3772-L3808","documentation":"Raised in bucketChunkReader.load when binary.Uvarint cannot decode the chunk's length header from the fetched bytes (n < 1). The bytes at the expected chunk offset are not a valid chunk header, indicating the fetched range is misaligned or the block data is corrupted/truncated.","triggerScenarios":"Thrown at pkg/store/bucket.go:3790 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify block/chunks integrity in object storage (checksums, complete upload)","Re-download the affected chunk range; check for truncated range reads","Confirm index offsets match the chunks file (no out-of-sync block files)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}