{"record":{"id":"c01cfee014403884","repo":"thanos-io/thanos","slug":"put-chunk","errorCode":null,"errorMessage":"put chunk","messagePattern":"put chunk","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compactv2/chunk_series_set.go","lineNumber":228,"sourceCode":"\t\t}\n\n\t\t// Skip the series with all deleted chunks.\n\t\tif len(chks) == 0 {\n\t\t\t// All series will be ignored.\n\t\t\tp.SeriesProcessed()\n\t\t\tcontinue\n\t\t}\n\n\t\tif err := sWriter.WriteChunks(chks...); err != nil {\n\t\t\treturn errors.Wrap(err, \"write chunks\")\n\t\t}\n\t\tif err := sWriter.AddSeries(ref, s.Labels(), chks...); err != nil {\n\t\t\treturn errors.Wrap(err, \"add series\")\n\t\t}\n\t\tfor _, chk := range chks {\n\t\t\t// ChunkPool is used by tsdb.OpenBlock BlockReader.\n\t\t\tif err := w.chunkPool.Put(chk.Chunk); err != nil {\n\t\t\t\treturn errors.Wrap(err, \"put chunk\")\n\t\t\t}\n\t\t}\n\t\tref++\n\t\tp.SeriesProcessed()\n\t}\n\tif populatedSet.Err() != nil {\n\t\treturn errors.Wrap(populatedSet.Err(), \"iterate populated chunk series set\")\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":210,"sourceCodeEnd":240,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/compactv2/chunk_series_set.go#L210-L240","documentation":"w.chunkPool.Put failed while returning a written chunk to the chunk pool after it was added to the index. The pool rejects chunks whose concrete type/size doesn't match the pool's expectations, indicating an unexpected chunk type reached the writer.","triggerScenarios":"write() loops over written chunks and calls chunkPool.Put(chk.Chunk); failure when the chunk is not one of the pooled types (e.g. an errChunk or XOR chunk with unexpected encoding, or nil chunk), because the pool validates the chunk's class/size before recycling.","commonSituations":"A populate error turned the chunk into errChunk and it still flowed to Put, custom chunk encodings not supported by the pool, compaction of blocks with newer/unknown chunk format versions.","solutions":["Check the wrapped cause: it usually names the rejected chunk type; ensure source blocks use supported chunk encodings (XOR).","Verify no error chunks (errChunk from failed populate) are passed onward — fail the compaction before Put when population failed.","Align Thanos/Prometheus versions: blocks written by newer TSDB formats may carry unsupported encodings.","If non-fatal in your flow, treat Put failures as a leak (skip) but log — though upstream expects a hard error."],"exampleFix":"// before: error chunks reach the pool and fail Put\nif err := w.chunkPool.Put(chk.Chunk); err != nil {\n    return errors.Wrap(err, \"put chunk\")\n}\n// after: skip pooling for non-XOR/err chunks\nif ec, ok := chk.Chunk.(chunkenc.Chunk); ok && isSupportedPoolChunk(ec) {\n    if err := w.chunkPool.Put(ec); err != nil {\n        return errors.Wrap(err, \"put chunk\")\n    }\n}","handlingStrategy":"type-guard","validationCode":"// only pool chunks of a supported type\nswitch c := chk.Chunk.(type) {\ncase *chunkenc.XORChunk:\n    _ = pool.Put(c)\ndefault:\n    // do not pool unknown/err chunks\n}","typeGuard":"func poolableChunk(c chunkenc.Chunk) bool {\n    if _, isErr := c.(errChunk); isErr { return false }\n    return c != nil && c.Encoding() == chunkenc.EncXOR\n}","tryCatchPattern":"if err := Put(chk.Chunk); err != nil {\n    level.Warn(logger).Log(\"msg\", \"chunk not poolable; leaking (non-fatal)\", \"err\", err)\n    // do not abort compaction for a pool-miss\n}","preventionTips":["Keep Thanos and Prometheus/TDengine TSDB versions aligned to avoid unknown chunk encodings","Fail compaction on populate errors so errChunks never reach the pool","Only pool chunks whose encoding matches the pool's registered types","Add a guard test asserting pool input encodings in custom writer code"],"tags":["go","tsdb","chunk-pool","memory"],"backgroundTag":"type-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"}