{"record":{"id":"5f541722d654dae6","repo":"nats-io/nats-server","slug":"corrupt-wal-will-truncate","errorCode":null,"errorMessage":"Corrupt WAL, will truncate","messagePattern":"Corrupt WAL, will truncate","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/raft.go","lineNumber":612,"sourceCode":"\t\t\t\t\t\tn.warn(\"Misaligned WAL, will truncate\")\n\t\t\t\t\t}\n\t\t\t\t\t// Truncate to the snapshot or beginning if there is none.\n\t\t\t\t\ttruncateAndErr(n.pindex)\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tn.pterm, n.pindex = ae.pterm, ae.pindex\n\t\t\t\tif ae.commit > 0 && ae.commit > n.commit {\n\t\t\t\t\tn.commit = ae.commit\n\t\t\t\t}\n\t\t\t}\n\t\t\tif err != nil {\n\t\t\t\tn.warn(\"Could not load %d from WAL [%+v]: %v\", index, state, err)\n\t\t\t\t// Truncate to the previous correct entry.\n\t\t\t\ttruncateAndErr(index - 1)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tif ae.pindex != index-1 {\n\t\t\t\tn.warn(\"Corrupt WAL, will truncate\")\n\t\t\t\t// Truncate to the previous correct entry.\n\t\t\t\ttruncateAndErr(index - 1)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tn.processAppendEntry(ae, nil)\n\t\t\t// Check how much we have queued up so far to determine if we should pause.\n\t\t\tfor _, e := range ae.entries {\n\t\t\t\tqsz += len(e.Data)\n\t\t\t\tif qsz > maxQsz && !n.paused {\n\t\t\t\t\tn.PauseApply()\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tn.debug(\"Started (cluster size %d, quorum %d)\", n.csz, n.qn)\n\n\t// Check if we need to start in observer mode due to lame duck status.","sourceCodeStart":594,"sourceCodeEnd":630,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/raft.go#L594-L630","documentation":"During WAL replay, a successfully loaded entry's pindex did not equal index-1, i.e. the log chain has a gap or out-of-order entry (torn write mid-record can leave a load error instead; this is the variant where records decode but do not chain). The WAL is truncated to the previous correct entry.","triggerScenarios":"Thrown at server/raft.go:612 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["No action needed; the WAL is self-truncated to the last chained entry","Entries after the break are re-replicated from the leader","Investigate storage durability if misalignment recurs"],"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-08T10:18:20.063Z"}