benbjohnson/litestream · error

close level 0 ltx iterator: %w

Error message

close level 0 ltx iterator: %w

What it means

The deferred close of the level-0 LTX iterator in applyNewLTXFiles returned an error. The listing had already been consumed, so this indicates a resource teardown failure on the backend connection — usually a dropped connection during Close.

Source

Thrown at replica.go:875

			}
		}
	}
}

// applyNewLTXFiles polls for new LTX files and applies them to the database.
// It starts from level 0 and falls back to higher levels if there are gaps
// (e.g., level 0 files were compacted away).
func (r *Replica) applyNewLTXFiles(ctx context.Context, f *os.File, afterTXID ltx.TXID, pageSize uint32) (ltx.TXID, error) {
	currentTXID := afterTXID

	// Poll level 0 for the most recent incremental files.
	itr, err := r.Client.LTXFiles(ctx, 0, currentTXID+1, false)
	if err != nil {
		return currentTXID, fmt.Errorf("list level 0 ltx files: %w", err)
	}
	closeLevel0 := func(retErr error) (ltx.TXID, error) {
		if closeErr := itr.Close(); closeErr != nil {
			closeErr = fmt.Errorf("close level 0 ltx iterator: %w", closeErr)
			if retErr != nil {
				return currentTXID, errors.Join(retErr, closeErr)
			}
			return currentTXID, closeErr
		}
		return currentTXID, retErr
	}

	var sawLevel0 bool
	for itr.Next() {
		sawLevel0 = true
		info := itr.Item()

		// If there's a gap, try to fill it from higher compaction levels.
		if info.MinTXID > currentTXID+1 {
			bridgedTXID, err := r.fillFollowGap(ctx, f, currentTXID, info.MinTXID, pageSize)
			if err != nil {
				return closeLevel0(err)

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. Check backend connection stability
  2. The follow loop retries on the next poll interval
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at replica.go:875 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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