benbjohnson/litestream · error

write txid file: %w

Error message

write txid file: %w

What it means

In the follow loop, WriteTXIDFile failed after successfully applying new LTX files — the sidecar recording the new high-water TXID could not be written. Progress is applied to the DB but not durable for crash recovery; causes are disk/permission errors.

Source

Thrown at replica.go:852

	for {
		select {
		case <-ctx.Done():
			r.Logger().Info("follow mode stopped")
			return nil
		case <-ticker.C:
			newTXID, err := r.applyNewLTXFiles(ctx, f, lastTXID, pageSize)
			if err != nil {
				if ctx.Err() != nil {
					r.Logger().Info("follow mode stopped")
					return nil
				}
				consecutiveErrors++
				r.Logger().Error("follow: error applying updates", "err", err, "consecutive_errors", consecutiveErrors)
				continue
			}
			if newTXID > lastTXID {
				if err := WriteTXIDFile(outputPath, newTXID); err != nil {
					return fmt.Errorf("write txid file: %w", err)
				}
				r.Logger().Info("follow: applied updates", "from_txid", lastTXID, "to_txid", newTXID)
				lastTXID = newTXID
				consecutiveErrors = 0
			}
		}
	}
}

// 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 {

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. Check disk space and permissions on the sidecar path
  2. Restart litestream; crash recovery will validate the last successfully written TXID
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at replica.go:852 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/61924dfeacdd2ebb. Report an issue: GitHub.