{"record":{"id":"aa6b4dbd38b4a043","repo":"nats-io/nats-server","slug":"snapshot-with-last-index-0-is-invalid-cleaning-up","errorCode":null,"errorMessage":"Snapshot with last index 0 is invalid, cleaning up","messagePattern":"Snapshot with last index 0 is invalid, cleaning up","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/raft.go","lineNumber":2062,"sourceCode":"\tvar hb [highwayhash.Size64]byte\n\tif !bytes.Equal(lchk[:], n.hh.Sum(hb[:0])) {\n\t\tn.warn(\"Snapshot corrupt, checksums did not match\")\n\t\treturn nil, errSnapshotCorrupt\n\t}\n\n\tvar le = binary.LittleEndian\n\tlps := le.Uint32(buf[16:])\n\tsnap := &snapshot{\n\t\tlastTerm:  le.Uint64(buf[0:]),\n\t\tlastIndex: le.Uint64(buf[8:]),\n\t\tpeerstate: buf[20 : 20+lps],\n\t\tdata:      buf[20+lps : hoff],\n\t}\n\n\t// We had a bug in 2.9.12 that would allow snapshots on last index of 0.\n\t// Detect that and continue anyway, nothing else we can do about it.\n\tif snap.lastIndex == 0 {\n\t\tn.warn(\"Snapshot with last index 0 is invalid, cleaning up\")\n\t\tos.Remove(n.snapfile)\n\t\tn.snapfile = _EMPTY_\n\t\treturn nil, errNoSnapAvailable\n\t}\n\n\treturn snap, nil\n}\n\n// Leader returns if we are the leader for our group.\n// We use an atomic here now vs acquiring the read lock.\nfunc (n *raft) Leader() bool {\n\tif n == nil {\n\t\treturn false\n\t}\n\treturn n.leaderState.Load()\n}\n\n// LeaderSince returns how long we have been leader for,","sourceCodeStart":2044,"sourceCodeEnd":2080,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/raft.go#L2044-L2080","documentation":"The loaded snapshot has lastIndex == 0, produced by a bug in v2.9.12 that allowed empty snapshots. Such a snapshot carries no usable state, so it is cleaned up and the node proceeds without it (WAL/leader catchup re-establishes state).","triggerScenarios":"Thrown at server/raft.go:2062 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Upgrade from 2.9.12 to a fixed release","No data recovery needed: index-0 snapshots hold nothing of value","The node re-snapshots normally on next snapshot cycle"],"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-08T15:18:49.778Z"}