{"record":{"id":"1f62b2eb8b1e3043","repo":"thanos-io/thanos","slug":"allocate-chunk-bytes","errorCode":null,"errorMessage":"allocate chunk bytes","messagePattern":"allocate chunk bytes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/bucket.go","lineNumber":2542,"sourceCode":"\treturn buf.Bytes(), nil\n}\n\nfunc (b *bucketBlock) readChunkRange(ctx context.Context, seq int, off, length int64, chunkRanges byteRanges, logger log.Logger) (*[]byte, error) {\n\tif seq < 0 || seq >= len(b.chunkObjs) {\n\t\treturn nil, errors.Errorf(\"unknown segment file for index %d\", seq)\n\t}\n\n\t// Get a reader for the required range.\n\treader, err := b.bkt.GetRange(ctx, b.chunkObjs[seq], off, length)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"get range reader\")\n\t}\n\tdefer runutil.CloseWithLogOnErr(logger, reader, \"readChunkRange close range reader\")\n\n\t// Get a buffer from the pool.\n\tchunkBuffer, err := b.chunkPool.Get(chunkRanges.size())\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"allocate chunk bytes\")\n\t}\n\n\t*chunkBuffer, err = readByteRanges(reader, *chunkBuffer, chunkRanges)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn chunkBuffer, nil\n}\n\nfunc (b *bucketBlock) chunkRangeReader(ctx context.Context, seq int, off, length int64) (io.ReadCloser, error) {\n\tif seq < 0 || seq >= len(b.chunkObjs) {\n\t\treturn nil, errors.Errorf(\"unknown segment file for index %d\", seq)\n\t}\n\n\treturn b.bkt.GetRange(ctx, b.chunkObjs[seq], off, length)\n}\n","sourceCodeStart":2524,"sourceCodeEnd":2560,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/bucket.go#L2524-L2560","documentation":"readChunkRange requests a pooled buffer of exactly chunkRanges.size() bytes from b.chunkPool before reading byte ranges into it. If the pool (or its allocator) cannot allocate the buffer, the error is wrapped as 'allocate chunk bytes'. The pool errors when the requested size exceeds its maximum chunk size limit.","triggerScenarios":"chunkPool.Get(chunkRanges.size()) fails because the requested range size exceeds the pool's max size — i.e. the chunk ranges computed for the query are larger than the configured max-chunk-pool-bytes / max size per chunk.","commonSituations":"Very large chunk ranges requested due to huge queries or downsampling misconfiguration, max-chunk-pool-bytes set too low relative to block chunk sizes, corrupted index claiming oversized ranges.","solutions":["Increase --store.grpc.series-max-chunk-bytes and/or chunk pool limits in store-gateway config so requested chunk sizes fit.","Reduce query time range / series count or use downsampled blocks for long ranges.","Verify chunk size in the block meta/index is sane; oversized values indicate corrupt index files.","If a query legitimately needs huge chunks, split it into smaller sub-queries."],"exampleFix":"// before (flag too small for block chunk sizes)\nthanos store-gateway --store.grpc.series-max-chunk-bytes=16000\n// after\nthanos store-gateway --store.grpc.series-max-chunk-bytes=1048576","handlingStrategy":"validation","validationCode":"if chunkRanges.size() > maxChunkPoolBytes {\n\treturn fmt.Errorf(\"requested chunk range %d exceeds pool max %d\", chunkRanges.size(), maxChunkPoolBytes)\n}","typeGuard":"func fitsPool(size int, max int) bool { return size > 0 && size <= max }","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"allocate chunk bytes\") {\n\t// fall back to non-pooled allocation or reject query with a clear message\n}","preventionTips":["Set --store.grpc.series-max-chunk-bytes >= block chunk sizes","Tune max-chunk-pool-bytes to match workload","Use downsampled blocks for long-range queries"],"tags":["memory-allocation","thanos-store-gateway","chunk-pool"],"backgroundTag":"value-out-of-range","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"}