{"record":{"id":"183df5863332879f","repo":"nats-io/nats-server","slug":"could-not-parse-snapshot-peerstate-correctly","errorCode":null,"errorMessage":"Could not parse snapshot peerstate correctly","messagePattern":"Could not parse snapshot peerstate correctly","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/raft.go","lineNumber":4760,"sourceCode":"\t\t// Check if we are catching up. If we are here we know the leader did not have all of the entries\n\t\t// so make sure this is a snapshot entry. If it is not start the catchup process again since it\n\t\t// means we may have missed additional messages.\n\t\tif catchingUp {\n\t\t\t// This means we already entered into a catchup state but what the leader sent us did not match what we expected.\n\t\t\t// Snapshots and peerstate will always be together when a leader is catching us up in this fashion.\n\t\t\tif len(ae.entries) != 2 || ae.entries[0].Type != EntrySnapshot || ae.entries[1].Type != EntryPeerState {\n\t\t\t\tn.warn(\"Expected first catchup entry to be a snapshot and peerstate, will retry\")\n\t\t\t\tn.cancelCatchup()\n\t\t\t\tn.Unlock()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif ps, err := decodePeerState(ae.entries[1].Data); err == nil {\n\t\t\t\tn.processPeerState(ps)\n\t\t\t\t// Also need to copy from client's buffer.\n\t\t\t\tae.entries[0].Data = copyBytes(ae.entries[0].Data)\n\t\t\t} else {\n\t\t\t\tn.warn(\"Could not parse snapshot peerstate correctly\")\n\t\t\t\tn.cancelCatchup()\n\t\t\t\tn.Unlock()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\t// Inherit state from appendEntry with the leader's snapshot.\n\t\t\thadPreviousSnapshot := n.snapfile != _EMPTY_\n\n\t\t\tsnap := &snapshot{\n\t\t\t\tlastTerm:  ae.pterm,\n\t\t\t\tlastIndex: ae.pindex,\n\t\t\t\tpeerstate: encodePeerState(&peerState{n.peerNames(), n.csz, n.extSt}),\n\t\t\t\tdata:      ae.entries[0].Data,\n\t\t\t}\n\t\t\t// Install the leader's snapshot as our own.\n\t\t\tif err := n.installSnapshot(snap); err != nil {\n\t\t\t\tn.setWriteErrLocked(err)\n\t\t\t\tn.Unlock()","sourceCodeStart":4742,"sourceCodeEnd":4778,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/raft.go#L4742-L4778","documentation":"While processing a catchup batch that should contain exactly a snapshot entry and a peerstate entry, the peerstate could not be decoded from the received entry — the pair is malformed relative to what the leader should send. The node cannot apply partial peerstate, so the catchup is restarted rather than proceeding with bad membership data.","triggerScenarios":"Thrown at server/raft.go:4760 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry happens automatically via catchup restart","Check for version mismatch between leader and follower altering entry encoding","Report recurring parse failures with both node versions"],"exampleFix":null,"handlingStrategy":"validation","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"}