benbjohnson/litestream · error

fetch src level info: %w

Error message

fetch src level info: %w

What it means

Store.CompactDB failed fetching metadata about the newest LTX file at the source level (the level immediately below the destination) via db.MaxLTXFileInfo(ctx, srcLevel). Like the dst fetch, this enumerates LTX files on the replica storage, so errors are usually backend/network problems. The wrapped error is returned with %w.

Source

Thrown at store.go:808

			return nil, fmt.Errorf("fetch db position: %w", err)
		}
		if dstInfo.MaxTXID != 0 && dstInfo.MaxTXID >= pos.TXID {
			return nil, ErrNoCompaction
		}

		info, err := db.Snapshot(ctx)
		if err != nil {
			return info, err
		}
		db.Logger.InfoContext(ctx, "snapshot complete", "txid", info.MaxTXID.String(), "size", info.Size)
		return info, nil
	}

	// Fetch latest LTX files for both the source & destination so we can see if we need to make progress.
	srcLevel := s.levels.PrevLevel(dstLevel)
	srcInfo, err := db.MaxLTXFileInfo(ctx, srcLevel)
	if err != nil {
		return nil, fmt.Errorf("fetch src level info: %w", err)
	}

	// Skip if there are no new files to compact.
	if srcInfo.MaxTXID <= dstInfo.MinTXID {
		return nil, ErrNoCompaction
	}

	info, err := db.Compact(ctx, dstLevel)
	if err != nil {
		return info, err
	}

	db.Logger.InfoContext(ctx, "compaction complete",
		"level", dstLevel,
		slog.Group("txid",
			"min", info.MinTXID.String(),
			"max", info.MaxTXID.String(),
		),

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. Check the wrapped error from the replica client for storage-specific causes (auth, missing prefix, throttling).
  2. Increase context timeout for compaction operations on slow storage; verify network path to the backend.
  3. Confirm the replica contains the expected level directories (L0/L1/L2/snapshot); a wiped or partially restored replica can break listings.
  4. Retry; compaction monitors re-invoke CompactDB on the next schedule tick.

Example fix

// before
info, err := db.MaxLTXFileInfo(ctx, level)
// after
ctx, cancel := context.WithTimeout(ctx, 5*time.Minute)
defer cancel()
info, err := db.MaxLTXFileInfo(ctx, level)
if err != nil {
    return fmt.Errorf("fetch src level info: %w", err)
}
Defensive patterns

Strategy: retry

Validate before calling

ctx, cancel := context.WithTimeout(ctx, 5*time.Minute)
defer cancel()
// preflight listing before compaction
itr, err := replicaClient.LTXFiles(ctx, srcLevel, 0, false)
if err != nil {
    return fmt.Errorf("cannot list src level %d: %w", srcLevel, err)
}
itr.Close()

Try / catch

if _, err := store.CompactDB(ctx, db, dstLevel); err != nil {
    if errors.Is(err, context.DeadlineExceeded) {
        log.Printf("compaction listing timed out; retrying next cycle")
        return nil
    }
    return err
}

Prevention

When it happens

Trigger: CompactDB(ctx, db, dstLevel) where PrevLevel(dstLevel) lookup metadata fails: LTXFiles listing error from the replica client, cache miss plus remote listing failure, or a context cancellation/timeout during listing.

Common situations: Object-storage outages, expired credentials, request timeouts on large level listings, misconfigured replica client pointing at a nonexistent prefix, or context deadline exceeded on slow networks.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06). Data as JSON: /api/errors/e8cf6e85e7f31535. Report an issue: GitHub.