{"record":{"id":"6836dc4a5ea5dec7","repo":"nats-io/nats-server","slug":"detected-another-leader-with-higher-term-will-ste","errorCode":null,"errorMessage":"Detected another leader with higher term, will stepdown","messagePattern":"Detected another leader with higher term, will stepdown","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/raft.go","lineNumber":5022,"sourceCode":"\t\t\tn.sendHeartbeat()\n\t\t}\n\n\t\tarPool.Put(ar)\n\t} else if ar.reply != _EMPTY_ {\n\t\t// The remote node didn't commit the append entry, and they believe they\n\t\t// are behind and have specified a reply subject, so let's try to catch them up.\n\t\t// In this case ar.term was populated with the remote's pterm.\n\t\tn.catchupFollower(ar)\n\t} else {\n\t\tn.Lock()\n\t\tif ar.term > n.term {\n\t\t\t// The remote node didn't commit the append entry, it looks like\n\t\t\t// they are on a newer term than we are. Step down.\n\t\t\t// In this case ar.term was populated with the remote's term.\n\t\t\tn.term = ar.term\n\t\t\tn.vote = noVote\n\t\t\tn.writeTermVote()\n\t\t\tn.warn(\"Detected another leader with higher term, will stepdown\")\n\t\t\tn.stepdownLocked(noLeader)\n\t\t}\n\t\tn.Unlock()\n\t\t// Either way, return back to pool.\n\t\tarPool.Put(ar)\n\t}\n}\n\n// handleAppendEntryResponse processes responses to append entries.\nfunc (n *raft) handleAppendEntryResponse(sub *subscription, c *client, _ *Account, subject, reply string, msg []byte) {\n\tar := decodeAppendEntryResponse(msg)\n\tif ar == nil {\n\t\tn.error(\"Received malformed append entry response\")\n\t\treturn\n\t}\n\tar.reply = reply\n\tn.resp.push(ar)\n}","sourceCodeStart":5004,"sourceCodeEnd":5040,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/raft.go#L5004-L5040","documentation":"An append-entry response carried a term higher than this node's current term (the responder is on a newer term). The node adopts the higher term, clears its vote, and steps down as leader — standard Raft behavior to converge on the newest term rather than continue an illegitimate leadership.","triggerScenarios":"Thrown at server/raft.go:5022 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["No action needed; a new election in the higher term resolves leadership","Frequent occurrences suggest network partitions or a reinstated node with persisted newer state","Verify no removed node keeps rejoining with divergent state"],"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"}