{"record":{"id":"31059488353d10f6","repo":"nats-io/nats-server","slug":"not-granting-vote-for-q-could-not-persist-term-a","errorCode":null,"errorMessage":"Not granting vote for %q, could not persist term and vote: %v","messagePattern":"Not granting vote for %q, could not persist term and vote: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/raft.go","lineNumber":5652,"sourceCode":"\tvoteOk := n.vote == noVote || n.vote == vr.candidate\n\n\t// If we have an empty log, but are initializing.\n\tif voteOk && vresp.empty && n.initializing {\n\t\t// Reset notion of having an empty log if we're voting during initialization/scale up.\n\t\t// Ensures they only need quorum, and not need to hear from all servers.\n\t\tvresp.empty = false\n\t}\n\n\t// Other server's log needs to be equal or more up-to-date than ours.\n\tif voteOk && (vr.lastTerm > n.pterm || vr.lastTerm == n.pterm && vr.lastIndex >= n.pindex) {\n\t\t// Persist our vote before granting it. Raft requires the vote to be durable before\n\t\t// we respond, otherwise a restart could forget the vote and let us grant a second\n\t\t// vote in the same term, which would break election safety.\n\t\tn.term = vr.term\n\t\tn.vote = vr.candidate\n\t\tif err := n.writeTermVote(); err != nil {\n\t\t\tn.vote = noVote\n\t\t\tn.warn(\"Not granting vote for %q, could not persist term and vote: %v\", n.group, err)\n\t\t} else {\n\t\t\tvresp.granted = true\n\t\t\tn.resetElectionTimeout()\n\t\t}\n\t} else if n.vote == noVote && n.State() != Candidate {\n\t\t// We have a more up-to-date log, and haven't voted yet.\n\t\t// Start campaigning earlier, but only if not candidate already, as that would short-circuit us.\n\t\tn.resetElect(randCampaignTimeout())\n\t}\n\n\t// Term might have changed, make sure response has the most current\n\tvresp.term = n.term\n\n\tn.Unlock()\n\n\tn.sendReply(vr.reply, vresp.encode())\n\n\treturn nil","sourceCodeStart":5634,"sourceCodeEnd":5670,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/raft.go#L5634-L5670","documentation":"A candidate/leader could not persist its term+vote before granting a vote (writeTermVote failed). Per Raft safety the vote is simply not granted — the candidate's up-to-date log alone is not sufficient — and the requester must obtain a quorum elsewhere or in a later round.","triggerScenarios":"Thrown at server/raft.go:5652 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the underlying persistence failure (disk full, permissions, I/O error)","The requester will retry or win via other voters; no manual intervention needed for transient errors","Recurring failures on all nodes prevent elections — repair storage first"],"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"}