{"record":{"id":"f0c4a798ffcb9e6e","repo":"nats-io/nats-server","slug":"error-removing-snapshots-directory-during-reset","errorCode":null,"errorMessage":"Error removing snapshots directory during reset: %v","messagePattern":"Error removing snapshots directory during reset: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/raft.go","lineNumber":2550,"sourceCode":"\t// Cancel any in-flight catchup so it does not race the reset.\n\tn.cancelCatchup()\n\n\t// Drop proposals and inbound entries; they are no longer meaningful\n\t// against whatever log this node ends up following.\n\tn.prop.drain()\n\tn.entry.drain()\n\tn.resp.drain()\n\tn.apply.drain()\n\tn.reqs.drain()\n\tn.votes.drain()\n\n\t// Remove every snapshot under our snapshots dir, not just the one referenced\n\t// by n.snapfile. Orphans (e.g. from a crash between install and the previous\n\t// file's removal) would otherwise be picked up by setupLastSnapshot on the\n\t// next restart and reseed the state we are discarding here.\n\tsnapDir := filepath.Join(n.sd, snapshotsDir)\n\tif err := os.RemoveAll(snapDir); err != nil {\n\t\tn.warn(\"Error removing snapshots directory during reset: %v\", err)\n\t}\n\tif err := os.MkdirAll(snapDir, defaultDirPerms); err != nil {\n\t\tn.warn(\"Error recreating snapshots directory during reset: %v\", err)\n\t}\n\tn.snapfile = _EMPTY_\n\n\t// Abort any inflight async snapshot checkpoint.\n\tn.snapshotting = false\n\n\t// Reset the WAL, but reset these first to not trip the assertion.\n\tn.commit, n.hcommit, n.applied, n.processed, n.papplied = 0, 0, 0, 0, 0\n\tn.resetWAL()\n\n\t// Reset peer set to just ourselves; a new leader will fold us back into\n\t// the cluster's membership view via processPeerState.\n\tn.peers = map[string]*lps{n.id: {time.Time{}, 0}}\n\tn.removed = nil\n\tn.adjustClusterSizeAndQuorum()","sourceCodeStart":2532,"sourceCodeEnd":2568,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/raft.go#L2532-L2568","documentation":"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.","triggerScenarios":"Thrown at server/raft.go:2550 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check directory permissions and ensure the process owns the snapshots dir","Look for external locks (NFS, containers, antivirus) preventing unlink and retry removal","Manually remove orphaned snapshot files after shutdown if the warning persists"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}