Skip to content

fix: only refresh election timer when vote is granted#281

Merged
sakno merged 1 commit intodotnet:developfrom
specula-org:fix/vote-timer-reset-on-grant
Mar 27, 2026
Merged

fix: only refresh election timer when vote is granted#281
sakno merged 1 commit intodotnet:developfrom
specula-org:fix/vote-timer-reset-on-grant

Conversation

@Qian-Cheng-nju
Copy link
Copy Markdown

Hi again! I noticed a small performance improvement opportunity in VoteAsync while reading the code.

Currently in RaftCluster.cs, the election timer is refreshed (line 827) before checking whether the vote is actually granted (line 834). This means a rejected RequestVote still resets the follower's election timer, which can delay elections unnecessarily in split-vote scenarios — the follower keeps getting its timer refreshed by candidates it doesn't vote for.

The Raft paper only resets the election timer when a vote is actually granted. This change moves the Refresh() call to after the vote decision, so only granted votes refresh the timer.

@sakno
Copy link
Copy Markdown
Collaborator

sakno commented Mar 27, 2026

Many thanks!

@sakno sakno merged commit 21f8259 into dotnet:develop Mar 27, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants