{"record":{"id":"3acfd82d682d5265","repo":"hyperledger/fabric","slug":"failed-to-create-snapshot-from-memorystorage-s","errorCode":null,"errorMessage":"failed to create snapshot from MemoryStorage: %s","messagePattern":"failed to create snapshot from MemoryStorage: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"orderer/consensus/etcdraft/storage.go","lineNumber":303,"sourceCode":"\n\tif err := rs.snap.SaveSnap(snap); err != nil {\n\t\treturn errors.Errorf(\"failed to save snapshot to disk: %s\", err)\n\t}\n\n\trs.lg.Debugf(\"Releasing lock to wal files prior to %d\", snap.GetMetadata().GetIndex())\n\tif err := rs.wal.ReleaseLockTo(snap.GetMetadata().GetIndex()); err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\n// TakeSnapshot takes a snapshot at index i from MemoryStorage, and persists it to wal and disk.\nfunc (rs *RaftStorage) TakeSnapshot(i uint64, cs *raftpb.ConfState, data []byte) error {\n\trs.lg.Debugf(\"Creating snapshot at index %d from MemoryStorage\", i)\n\tsnap, err := rs.ram.CreateSnapshot(i, cs, data)\n\tif err != nil {\n\t\treturn errors.Errorf(\"failed to create snapshot from MemoryStorage: %s\", err)\n\t}\n\n\tif err = rs.saveSnap(snap); err != nil {\n\t\treturn err\n\t}\n\n\trs.snapshotIndex = append(rs.snapshotIndex, snap.GetMetadata().GetIndex())\n\n\t// Keep some entries in memory for slow followers to catchup\n\tif i > rs.SnapshotCatchUpEntries {\n\t\tcompacti := i - rs.SnapshotCatchUpEntries\n\t\trs.lg.Debugf(\"Purging in-memory raft entries prior to %d\", compacti)\n\t\tif err = rs.ram.Compact(compacti); err != nil {\n\t\t\tif err == raft.ErrCompacted {\n\t\t\t\trs.lg.Warnf(\"Raft entries prior to %d are already purged\", compacti)\n\t\t\t} else {\n\t\t\t\trs.lg.Fatalf(\"Failed to purge raft entries: %s\", err)\n\t\t\t}","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/orderer/consensus/etcdraft/storage.go#L285-L321","documentation":"TakeSnapshot requests a snapshot at index i from the in-memory raft MemoryStorage (ram.CreateSnapshot). MemoryStorage rejects the request (e.g. the index is out of range of its raft log, or an existing snapshot at that index already has conflicting data), and the error is wrapped with this message.","triggerScenarios":"takeSnapshot called with an index i that MemoryStorage cannot snapshot: i is greater than the last applied/compacted state or i <= an already existing snapshot's index (ErrSnapOutOfDate), or ConfState/data inconsistent with the log.","commonSituations":"Bug or race in the caller computing the snapshot index (e.g. double snapshot request for the same index); node replaying/refreshing state where the in-memory log was already compacted; mis-tuned SizePerSnapshot causing snapshot triggers at invalid indices.","solutions":["Check the orderer log for the wrapped underlying error (snapshot out of date vs out-of-range index)","Verify the snapshot index logic in the node's apply loop — ensure each index is snapshotted exactly once and after it is committed","Restart the node if in-memory state and disk state diverged","Report/pin the fabric version; if reproducible at steady state, check for known etcdraft bugs in your Hyperledger Fabric release"],"exampleFix":"// before\nsnap, err := rs.ram.CreateSnapshot(i, cs, data)\nif err != nil {\n\treturn errors.Errorf(\"failed to create snapshot from MemoryStorage: %s\", err)\n}\n// after\nevaluator := func() error { return rs.TakeSnapshot(i, cs, data) }\nif err := evaluator(); err != nil {\n\tlg.Warnf(\"snapshot at index %d skipped: %s\", i, err) // do not crash on duplicate snapshot request\n}\n","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := storage.TakeSnapshot(i, cs, data); err != nil {\n\tvar snapOutOfDate bool\n\tif strings.Contains(err.Error(), \"ErrSnapOutOfDate\") || strings.Contains(err.Error(), \"snapshot out of date\") {\n\t\tsnapOutOfDate = true // duplicate/superseded snapshot request — safe to skip\n\t}\n\tif !snapOutOfDate {\n\t\treturn err\n\t}\n\tlg.Warnf(\"snapshot at index %d already superseded, skipping\", i)\n}","preventionTips":["Trigger snapshots exactly once per index (guard with lastSnapshottedIndex)","Verify snapshot indices are derived from committed/applied entries only","Keep SizePerSnapshot settings sane for channel volume","If reproducible, check for known etcdraft bugs in your Fabric release"],"tags":["raft","snapshot","memory-storage","index"],"backgroundTag":"snapshot-index-out-of-range","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}