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

Conversation

mprimi
Copy link
Contributor

@mprimi mprimi commented Jan 31, 2024

A node's Term may be increased during handling of a VoteRequest. When that was the case, the node was responding with a stale Term.

Example trace:

[DBG] RAFT [S1Nunr6R - S-R3F-5xgoWjQW] Received a voteRequest &{term:27 lastTerm:26 lastIndex:46 candidate:yrzKKRBu reply:$NRG.R.OHF7VRUO}
[DBG] RAFT [S1Nunr6R - S-R3F-5xgoWjQW] Stepping down from leader, detected higher term: 27 vs 26
[DBG] RAFT [S1Nunr6R - S-R3F-5xgoWjQW] Stepping down
[DBG] RAFT [S1Nunr6R - S-R3F-5xgoWjQW] Switching to follower
[DBG] RAFT [S1Nunr6R - S-R3F-5xgoWjQW] Sending a voteResponse &{term:26 peer:S1Nunr6R granted:true} -> "$NRG.R.OHF7VRUO"

This is handled correctly except VoteResponse in the last log line should be sending back Term 27, not 26.

Signed-off-by: Your Name marco@nats.io

@mprimi mprimi requested a review from a team as a code owner January 31, 2024 23:53
@derekcollison
Copy link
Member

Seems this test not always fails - TestNRGSimpleElection

Make sure you can get a green run on branch before posting PR.

@mprimi mprimi marked this pull request as draft February 1, 2024 04:23
Copy link
Member

@neilalexander neilalexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right thing to do? The vote response term should surely always correspond with the vote request, otherwise the vote responses may appear to be unsolicited for the new term.

Additionally, nodes receiving a vote response when in candidate state will simply ignore the response if the term is less than the current term, see L2943: if vresp.granted && nterm >= vresp.term {

Have checked this against another Raft implementation and think it's OK, will fix the test.

mprimi and others added 2 commits February 1, 2024 17:13
A node's Term may be increased during handling of a VoteRequest.
When that was the case, the node was responding with a stale Term.
@derekcollison
Copy link
Member

@mprimi feel free to convert from draft and will merge. Thanks!

@mprimi mprimi marked this pull request as ready for review February 1, 2024 21:57
Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@derekcollison derekcollison merged commit ba14d03 into main Feb 1, 2024
4 checks passed
@derekcollison derekcollison deleted the marco/raft-vote-term branch February 1, 2024 22:15
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.

None yet

3 participants