nats-io/nats-server · error

Error removing snapshots directory during reset: %v

Error message

Error removing snapshots directory during reset: %v

What it means

os.RemoveAll on the snapshots directory failed during a WAL/log reset. The reset is discarding all state to re-follow a leader, but stale snapshot files could not be cleaned up; leftover orphans risk being picked up by setupLastSnapshot on the next restart and reseeding discarded state.

Source

Thrown at server/raft.go:2550

	// Cancel any in-flight catchup so it does not race the reset.
	n.cancelCatchup()

	// Drop proposals and inbound entries; they are no longer meaningful
	// against whatever log this node ends up following.
	n.prop.drain()
	n.entry.drain()
	n.resp.drain()
	n.apply.drain()
	n.reqs.drain()
	n.votes.drain()

	// Remove every snapshot under our snapshots dir, not just the one referenced
	// by n.snapfile. Orphans (e.g. from a crash between install and the previous
	// file's removal) would otherwise be picked up by setupLastSnapshot on the
	// next restart and reseed the state we are discarding here.
	snapDir := filepath.Join(n.sd, snapshotsDir)
	if err := os.RemoveAll(snapDir); err != nil {
		n.warn("Error removing snapshots directory during reset: %v", err)
	}
	if err := os.MkdirAll(snapDir, defaultDirPerms); err != nil {
		n.warn("Error recreating snapshots directory during reset: %v", err)
	}
	n.snapfile = _EMPTY_

	// Abort any inflight async snapshot checkpoint.
	n.snapshotting = false

	// Reset the WAL, but reset these first to not trip the assertion.
	n.commit, n.hcommit, n.applied, n.processed, n.papplied = 0, 0, 0, 0, 0
	n.resetWAL()

	// Reset peer set to just ourselves; a new leader will fold us back into
	// the cluster's membership view via processPeerState.
	n.peers = map[string]*lps{n.id: {time.Time{}, 0}}
	n.removed = nil
	n.adjustClusterSizeAndQuorum()

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Check directory permissions and ensure the process owns the snapshots dir
  2. Look for external locks (NFS, containers, antivirus) preventing unlink and retry removal
  3. Manually remove orphaned snapshot files after shutdown if the warning persists
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at server/raft.go:2550 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/f0c4a798ffcb9e6e. Report an issue: GitHub.