Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAFT node responds to VoteRequest with outdated Term #5021

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -3953,6 +3953,10 @@ func (n *raft) processVoteRequest(vr *voteRequest) error {
n.resetElect(randCampaignTimeout())
}
}

// Term might have changed, make sure response has the most current
vresp.term = n.term

n.Unlock()

n.sendReply(vr.reply, vresp.encode())
Expand Down
12 changes: 5 additions & 7 deletions server/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,13 @@ func TestNRGSimpleElection(t *testing.T) {
re := decodeVoteResponse(msg.Data)
require_True(t, re != nil)

// The new term hasn't started yet, so the vote responses
// should contain the term from before the election. It is
// possible that candidates are listening to this to work
// out if they are in previous terms.
require_Equal(t, re.term, vr.lastTerm)
require_Equal(t, re.term, startTerm)

// The vote should have been granted.
require_Equal(t, re.granted, true)

// The node granted the vote, therefore the term in the vote
// response should have advanced as well.
require_Equal(t, re.term, vr.term)
require_Equal(t, re.term, startTerm+1)
}

// Everyone in the group should have voted for our candidate
Expand Down