{"record":{"id":"03fa8375c90cdd31","repo":"thanos-io/thanos","slug":"open-index","errorCode":null,"errorMessage":"open index","messagePattern":"open index","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/block/index.go","lineNumber":440,"sourceCode":"\tresid = ulid.MustNew(ulid.Now(), entropy)\n\n\tmeta, err := metadata.ReadFromDir(bdir)\n\tif err != nil {\n\t\treturn resid, errors.Wrap(err, \"read meta file\")\n\t}\n\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))","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/index.go#L422-L458","documentation":"block.Repair wraps the error returned by b.Index(), which opens a read handle over the block's index file after the block was successfully opened. Failure means the index file exists but cannot be read/parsed into an index reader — typically decoding errors from corruption. Wrapped as 'open index: <cause>'.","triggerScenarios":"Repair on a block whose index file is corrupt (e.g. the tsdb issue-347 out-of-order-chunk corruption that Repair targets), truncated during transfer, or whose TOC/symbols sections are damaged; disk read errors mid-open.","commonSituations":"Blocks affected by the Prometheus tsdb#347 bug where the index is malformed enough that even opening a reader fails; blocks uploaded while Prometheus was still writing them (rare, but seen with unsafe tooling); partial restore from backup.","solutions":["Read the wrapped cause; if it indicates index decoding corruption, verify with `thanos tools bucket verify` on the bucket or a local index inspection.","Re-fetch the block from object storage and compare checksums; retry Repair on the intact copy.","If no intact copy exists, delete the block and regenerate data from the source Prometheus (re-upload or re-compact).","Keep Repair as a last resort: prefer preventing issue-347 corruption by upgrading Prometheus past the bug."],"exampleFix":"// before\n_, err = block.RepairIssue347(ctx, logger, dir, id, source)\n// treat as transient and retry forever\n// after\n_, err = block.RepairIssue347(ctx, logger, dir, id, source)\nif err != nil && strings.Contains(err.Error(), \"open index\") {\n    // index unreadable: re-download block once, then fail permanently\n    if derr := redownloadBlock(ctx, bucket, dir, id); derr != nil {\n        return derr\n    }\n    _, err = block.RepairIssue347(ctx, logger, dir, id, source)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"resid, err := block.RepairIssue347(ctx, logger, dir, id, source)\nif err != nil && strings.Contains(err.Error(), \"open index\") {\n    // index unreadable: quarantine the block instead of retrying\n    if qerr := quarantineBlock(dir, id); qerr != nil {\n        return resid, qerr\n    }\n    return resid, fmt.Errorf(\"block %s quarantined: index unreadable\", id)\n}","preventionTips":["Upgrade Prometheus/Thanos past the tsdb#347 bug so corrupt indexes are not produced.","Run `thanos tools bucket verify` periodically to catch unreadable indexes early.","Alert on repair failures containing 'open index' — they indicate non-self-healing corruption.","Keep block replicas in object storage so an unreadable index can be restored."],"tags":["thanos","tsdb","index-corruption","file-read-failed"],"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"}