{"record":{"id":"a2baa9e1f873cb7b","repo":"nats-io/nats-server","slug":"error-writing-peer-state-file-for-q-v","errorCode":null,"errorMessage":"Error writing peer state file for %q: %v","messagePattern":"Error writing peer state file for %q: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/raft.go","lineNumber":5390,"sourceCode":"\t\tlastIndex: le.Uint64(msg[16:]),\n\t\tcandidate: string(copyBytes(msg[24 : 24+idLen])),\n\t\treply:     reply,\n\t}\n}\n\nconst peerStateFile = \"peers.idx\"\n\n// Lock should be held.\nfunc (n *raft) writePeerState(ps *peerState) {\n\tpse := encodePeerState(ps)\n\tif bytes.Equal(n.wps, pse) {\n\t\treturn\n\t}\n\t// Stamp latest and write the peer state file.\n\tn.wps = pse\n\tif err := writePeerState(n.dios, n.sd, ps); err != nil && !n.isClosed() {\n\t\tn.setWriteErrLocked(err)\n\t\tn.warn(\"Error writing peer state file for %q: %v\", n.group, err)\n\t}\n}\n\n// Writes out our peer state outside of a specific raft context.\nfunc writePeerState(dios *diskIOSemaphore, sd string, ps *peerState) error {\n\tpsf := filepath.Join(sd, peerStateFile)\n\tif _, err := os.Stat(psf); err != nil && !os.IsNotExist(err) {\n\t\treturn err\n\t}\n\treturn writeFileWithSync(dios, psf, encodePeerState(ps), defaultFilePerms)\n}\n\nfunc readPeerState(dios *diskIOSemaphore, sd string) (ps *peerState, err error) {\n\tdios.acquire()\n\tbuf, err := os.ReadFile(filepath.Join(sd, peerStateFile))\n\tdios.release()\n\n\tif err != nil {","sourceCodeStart":5372,"sourceCodeEnd":5408,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/raft.go#L5372-L5408","documentation":"writePeerState failed to persist the peers.idx file (encoded peer membership) for this RAFT group; the error was also latched via setWriteErrLocked. The in-memory n.wps is already updated, so disk state may diverge from memory until a successful rewrite.","triggerScenarios":"Thrown at server/raft.go:5390 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check write permissions and disk space in the RAFT store dir","The next successful peer-state change will retry the write since wtv-style caching still forces a rewrite on failure","Restart after fixing storage so peer state is re-persisted"],"exampleFix":null,"handlingStrategy":"retry","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"}