nats-io/nats-server · error

Draining and replaying snapshot

Error message

Draining and replaying snapshot

What it means

Operational notice: DrainAndReplaySnapshot is pausing the apply queue, draining pending entries, and loading the last snapshot to replay state from it (used when upper-layer state must be rebuilt from the snapshot). The highest known commit is preserved; the caller must call ResumeApply after handling the snapshot.

Source

Thrown at server/raft.go:1473

	}
}

// DrainAndReplaySnapshot will drain the apply queue and replay the snapshot.
// Our highest known commit will be preserved by pausing applies. The caller
// should make sure to call ResumeApply() when handling the snapshot from the
// queue, which will populate the rest of the committed entries in the queue.
func (n *raft) DrainAndReplaySnapshot() bool {
	n.Lock()
	defer n.Unlock()
	// If the node was deleted, we can't replay the snapshot.
	if n.deleted {
		return false
	}
	snap, err := n.loadLastSnapshot()
	if err != nil {
		return false
	}
	n.warn("Draining and replaying snapshot")
	n.pauseApplyLocked()
	n.apply.drain()
	// Cancel after draining, we might have sent EntryCatchup and need to get them the nil entry.
	n.cancelCatchup()
	n.commit = snap.lastIndex
	n.apply.push(newCommittedEntry(n.commit, []*Entry{{EntrySnapshot, snap.data}}))
	return true
}

// Applied is a callback that must be called by the upper layer when it
// has successfully applied the committed entries that it received from the
// apply queue. It will return the number of entries and an estimation of the
// byte size that could be removed with a snapshot/compact.
func (n *raft) Applied(index uint64) (entries uint64, bytes uint64) {
	return n.Processed(index, index)
}

// Processed is a callback that must be called by the upper layer when it

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. No action needed; replay restores state machine from the snapshot
  2. Watch for the error path where loadLastSnapshot fails, which aborts replay
  3. Used during recovery flows — check preceding logs if unexpected
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at server/raft.go:1473 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02). Data as JSON: /api/errors/c426cbeb523a41a6. Report an issue: GitHub.