{"record":{"id":"d15eae48ed0adcbc","repo":"nats-io/nats-server","slug":"wrong-index-ae-is-v-index-stored-was-d-n-pin","errorCode":null,"errorMessage":"Wrong index, ae is %+v, index stored was %d, n.pindex is %d, will reset","messagePattern":"Wrong index, ae is %\\+v, index stored was (.+?), n\\.pindex is (.+?), will reset","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/raft.go","lineNumber":5070,"sourceCode":"// Store our append entry to our WAL.\n// lock should be held.\nfunc (n *raft) storeToWAL(ae *appendEntry) error {\n\tif ae == nil {\n\t\treturn fmt.Errorf(\"raft: Missing append entry for storage\")\n\t}\n\tif n.werr != nil {\n\t\treturn n.werr\n\t}\n\n\tseq, _, err := n.wal.StoreMsg(_EMPTY_, nil, ae.buf, 0)\n\tif err != nil {\n\t\tn.setWriteErrLocked(err)\n\t\treturn err\n\t}\n\n\t// Sanity checking for now.\n\tif index := ae.pindex + 1; index != seq {\n\t\tn.warn(\"Wrong index, ae is %+v, index stored was %d, n.pindex is %d, will reset\", ae, seq, n.pindex)\n\t\tif n.State() == Leader {\n\t\t\tn.stepdownLocked(n.selectNextLeader())\n\t\t}\n\t\t// Reset and cancel any catchup.\n\t\tn.resetWAL()\n\t\tn.cancelCatchup()\n\t\treturn errEntryStoreFailed\n\t}\n\n\tn.bytes += n.entryStoreSize(ae)\n\tn.pterm = ae.term\n\tn.pindex = seq\n\treturn nil\n}\n\nconst (\n\tpauseQuorumThreshold = 100_000\n\tpauseQuorumBytes     = 1 * 1024 * 1024 * 1024 // 1GB","sourceCodeStart":5052,"sourceCodeEnd":5088,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/raft.go#L5052-L5088","documentation":"After StoreMsg, the WAL-assigned sequence does not equal ae.pindex+1 — the log's physical sequence and the entry chain have diverged (indicates WAL inconsistency or a bug). As a defensive measure the node steps down if leader and resets so state is re-derived from a consistent point.","triggerScenarios":"Thrown at server/raft.go:5070 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Treat as corruption: allow the reset/re-sync to repair the WAL","Check storage health for the root cause of sequence divergence","Report with logs if it reproduces on healthy disks — it marks a serious invariant break"],"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"}