{"record":{"id":"8b9df201d27a13bd","repo":"thanos-io/thanos","slug":"open-chunks","errorCode":null,"errorMessage":"open chunks","messagePattern":"open chunks","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/block/index.go","lineNumber":446,"sourceCode":"\tif meta.Thanos.Downsample.Resolution > 0 {\n\t\treturn resid, errors.New(\"cannot repair downsampled block\")\n\t}\n\n\tb, err := tsdb.OpenBlock(logutil.GoKitLogToSlog(logger), bdir, nil, nil)\n\tif err != nil {\n\t\treturn resid, errors.Wrap(err, \"open block\")\n\t}\n\tdefer runutil.CloseWithErrCapture(&err, b, \"repair block reader\")\n\n\tindexr, err := b.Index()\n\tif err != nil {\n\t\treturn resid, errors.Wrap(err, \"open index\")\n\t}\n\tdefer runutil.CloseWithErrCapture(&err, indexr, \"repair index reader\")\n\n\tchunkr, err := b.Chunks()\n\tif err != nil {\n\t\treturn resid, errors.Wrap(err, \"open chunks\")\n\t}\n\tdefer runutil.CloseWithErrCapture(&err, chunkr, \"repair chunk reader\")\n\n\tresdir := filepath.Join(dir, resid.String())\n\n\tchunkw, err := chunks.NewWriter(filepath.Join(resdir, ChunksDirname))\n\tif err != nil {\n\t\treturn resid, errors.Wrap(err, \"open chunk writer\")\n\t}\n\tdefer runutil.CloseWithErrCapture(&err, chunkw, \"repair chunk writer\")\n\n\tindexw, err := index.NewWriter(context.TODO(), filepath.Join(resdir, IndexFilename))\n\tif err != nil {\n\t\treturn resid, errors.Wrap(err, \"open index writer\")\n\t}\n\tdefer runutil.CloseWithErrCapture(&err, indexw, \"repair index writer\")\n\n\t// TODO(fabxc): adapt so we properly handle the version once we update to an upstream","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/index.go#L428-L464","documentation":"block.Repair wraps the error from b.Chunks(), which opens a reader over the block's chunks/ segment files after the index opened fine. Failure indicates the chunk segment files (chunks/000001, ...) are missing, truncated, or fail CRC/decoding checks. Wrapped as 'open chunks: <cause>'.","triggerScenarios":"Repair on a block with damaged or missing chunk segment files; segment files truncated by a partial upload/download; chunks dir removed or renamed; file permission or I/O errors when memory-mapping/reading segments.","commonSituations":"Blocks where a sync tool dropped some chunk segments; interrupted multipart upload to object storage; repairing a block restored from an incomplete backup; filesystem errors on the node running the repair job.","solutions":["Check chunks/ dir listing in the block dir: segment files must be contiguous and non-empty (use block.GetSegmentFiles).","Re-download the block from object storage, verifying file sizes/checksums, then retry Repair.","Check disk space and permissions on the node running Repair (ENOSPC/EACCES show up here).","If chunks are unrecoverable, delete the block and rebuild from source data."],"exampleFix":"// before\nsegfiles := block.GetSegmentFiles(bdir)\n_ = segfiles // assume segments are fine\nblock.RepairIssue347(ctx, logger, dir, id, source)\n// after\nsegfiles := block.GetSegmentFiles(bdir)\nif len(segfiles) == 0 {\n    return fmt.Errorf(\"block %s has no chunk segments: re-download before repair\", id)\n}","handlingStrategy":"validation","validationCode":"bdir := filepath.Join(dir, id.String())\nsegfiles := block.GetSegmentFiles(bdir)\nif len(segfiles) == 0 {\n    return fmt.Errorf(\"block %s has no chunk segments\", id)\n}\nfor _, sf := range segfiles {\n    if fi, err := os.Stat(sf); err != nil || fi.Size() == 0 {\n        return fmt.Errorf(\"chunk segment %s missing or empty\", sf)\n    }\n}","typeGuard":null,"tryCatchPattern":"resid, err := block.RepairIssue347(ctx, logger, dir, id, source)\nif err != nil && strings.Contains(err.Error(), \"open chunks\") {\n    if rerr := redownloadBlock(ctx, bucket, dir, id); rerr != nil {\n        return resid, err\n    }\n    resid, err = block.RepairIssue347(ctx, logger, dir, id, source)\n}","preventionTips":["Verify segment file contiguity and sizes after any block transfer.","Monitor disk space and I/O health on nodes running repair/compaction jobs.","Avoid repairing blocks restored from incomplete backups; restore fully first.","Use object-storage checksum verification on upload/download."],"tags":["thanos","tsdb","chunks","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"}