thanos-io/thanos · error

open index reader for block %+v

Error message

open index reader for block %+v

What it means

WriteSeries opens an index reader for each source block via b.Index(); failure is wrapped as "open index reader for block %+v" with the block metadata. This means the block's index file could not be opened or its reader could not be constructed.

Solutions

  1. Verify the block directory contains a readable index file (file size > 0, permissions OK)
  2. Check for concurrent deletion — ensure the block is not being removed by another compaction/retention process
  3. Run TSDB block verification/repair or delete the corrupt block and let TSDB re-fetch/rebuild if it is a replica
  4. Check disk health and filesystem errors in system logs
Defensive patterns

Strategy: validation

Validate before calling

for _, b := range readers {
    meta := b.Meta()
    if fi, err := os.Stat(filepath.Join(meta.ULID.String(), "index")); err != nil || fi.Size() == 0 {
        return fmt.Errorf("block %s index missing or empty", meta.ULID)
    }
}

Try / catch

if err := comp.WriteSeries(ctx, readers, sWriter, progress); err != nil {
    var target error
    if strings.Contains(err.Error(), "open index reader") {
        // quarantine/re-sync the offending block reported in the message
        logger.Error("failed to open index reader", "err", err)
    }
    return err
}

Prevention

When it happens

Trigger: b.Index() returns an error: index file missing/corrupt in the block directory, wrong permissions, block mid-deletion, or an index format the reader rejects.

Common situations: Corrupted TSDB block after crash or truncated download/copy; block directory being deleted concurrently by another process; manually copied blocks missing index file; permission problems on data volume.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/3b70f0a09fbfa2c3. Report an issue: GitHub.

Appendix: source

Thrown at pkg/compactv2/compactor.go:97

		return errors.New("cannot write from no readers")
	}

	var (
		sReaders []seriesReader
		closers  []io.Closer
	)
	defer func() {
		errs := tsdb_errors.NewMulti(err)
		if cerr := tsdb_errors.CloseAll(closers); cerr != nil {
			errs.Add(errors.Wrap(cerr, "close"))
		}
		err = errs.Err()
	}()

	for _, b := range readers {
		indexr, err := b.Index()
		if err != nil {
			return errors.Wrapf(err, "open index reader for block %+v", b.Meta())
		}
		closers = append(closers, indexr)

		chunkr, err := b.Chunks()
		if err != nil {
			return errors.Wrapf(err, "open chunk reader for block %+v", b.Meta())
		}
		closers = append(closers, chunkr)
		sReaders = append(sReaders, seriesReader{ir: indexr, cr: chunkr})
	}

	symbols, set, err := compactSeries(ctx, sReaders...)
	if err != nil {
		return errors.Wrapf(err, "compact series from %v", func() string {
			var metas []string
			for _, m := range readers {
				metas = append(metas, fmt.Sprintf("%v", m.Meta()))
			}

View on GitHub (pinned to 35b8b99117)