Do not update leader last-contact when granting a pre-vote request #609
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This fix a theoretical bug with pre-vote. The issue could happen when a former leader continuously send pre-vote requests to former followers before they get the chance to transition to Candidates without necessarily winning the pre-vote election (because they haven't got enough pre-vote granted for example). This could happen in a scenario when a node is misconfigured and have a low election timeout with a node configured differently from the others.
In that scenario, the pre-vote request will set the leader last contact in the node in follower state which prevent it from going to Candidate state and could render the cluster unstable for undetermined time.
Testing
I added an integration test that recreate the condition artificially. The test execute the following steps:
I executed the test with and without the fix and it consistently pass/fail based on it.