nats-io/nats-server · error
Error reading snapshot: %v
Error message
Error reading snapshot: %v
What it means
A warning logged by raft.loadLastSnapshot() when reading the node's snapshot file fails (os.ReadFile error such as missing, permission-denied, or I/O error). The function returns the error, so the node cannot restore from the last snapshot and must rely on WAL replay or peer catch-up.
Source
Thrown at server/raft.go:2031
if snap.lastIndex != n.papplied {
return 0, nil, errors.New("snapshot index mismatch")
}
return snap.lastIndex, snap.data, nil
}
// loadLastSnapshot will load and return our last snapshot.
// Lock should be held.
func (n *raft) loadLastSnapshot() (*snapshot, error) {
if n.snapfile == _EMPTY_ {
return nil, errNoSnapAvailable
}
n.dios.acquire()
buf, err := os.ReadFile(n.snapfile)
n.dios.release()
if err != nil {
n.warn("Error reading snapshot: %v", err)
return nil, err
}
if len(buf) < minSnapshotLen {
n.warn("Snapshot corrupt, too short")
return nil, errSnapshotCorrupt
}
// Check to make sure hash is consistent.
hoff := len(buf) - 8
lchk := buf[hoff:]
n.hh.Reset()
n.hh.Write(buf[:hoff])
var hb [highwayhash.Size64]byte
if !bytes.Equal(lchk[:], n.hh.Sum(hb[:0])) {
n.warn("Snapshot corrupt, checksums did not match")
return nil, errSnapshotCorrupt
}
View on GitHub (pinned to 3a66a489d2)
Solutions
- Check the snapshot file's existence and permissions at the path derived from the wrapped error
- Verify disk health for the raft storage directory
- If the snapshot is unrecoverable, resync the node from an intact peer
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at server/raft.go:2031 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/1e8df19fe41ee233.
Report an issue: GitHub.