Repository navigation
khepri_cluster: Handle a Ra server restart in parallel of a local reset - #440
Merged
Merged
Conversation
[Why] This is the variant taking a timeout as its third argument. It should have been exported from day 1. The documentation assumes that.
Codecov Reportβ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v0.17.x #440 +/- ##
===========================================
+ Coverage 90.08% 90.13% +0.05%
===========================================
Files 22 22
Lines 3559 3569 +10
===========================================
+ Hits 3206 3217 +11
+ Misses 353 352 -1
Flags with carried forward coverage won't be shown. Click here to find out more. β View full report in Codecov by Harness. π New features to boost your workflow:
|
dumbbell
force-pushed
the
fix-race-condition-during-cluster-join
branch
from
September 21, 2026 17:54
b61b4a4 to
c37d6fb
Compare
[Why] We had one occurence in the RabbitMQ CI of the following race condition: * The caller restarts the local Khepri store and asks it to rejoin a cluster. * As part of the cluster join, the local node is removed from the remote cluster and is reset locally. * It was already part of the target cluster and it receives an "Append entries" RPC upon restart which it does not expect because it was just reset. That's the race condition: the cluster removal and reset crossed the RPC. * Because the RPC was unexpected, the store crashes and it is restarted by its supervisor. At that point, Khepri did not handle the situation because it assumed the Ra server was terminated and it discarded the store properties stored in a `persistent_term`. So, this first join attempt returned an error near the end because the Ra server was restarted behind its back. Subsequent attempts by the caller to rejoin the cluster led to a `case_clause` exception in `check_status_and_join_locked/3` because the function does not expect the Ra server to run without store properties available. [How] To fix this, `reset_locally_and_join_locked/6` is split and modified to handle the fact that restarting the Ra server after a reset might return the `already_started` error. If this happens, the Ra server is forced to stop again and the start+join is tried again. The added testcase simulates the race condition by using meck and by sending the "Append entries" RPC to the Ra server. Therefore, it knows about Ra internals which is not great.
dumbbell
force-pushed
the
fix-race-condition-during-cluster-join
branch
from
September 21, 2026 18:24
c37d6fb to
ad1330e
Compare
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
We had one occurence in the RabbitMQ CI of the following race condition:
At that point, Khepri did not handle the situation because it assumed the Ra server was terminated and it discarded the store properties stored in a
persistent_term.So, this first join attempt returned an error near the end because the Ra server was restarted behind its back. Subsequent attempts by the caller to rejoin the cluster led to a
case_clauseexception incheck_status_and_join_locked/3because the function does not expect the Ra server to run without store properties available.How
To fix this,
reset_locally_and_join_locked/6is split and modified to handle the fact that restarting the Ra server after a reset might return thealready_startederror.If this happens, the Ra server is forced to stop again and the start+join is tried again.
The added testcase simulates the race condition by using meck and by sending the "Append entries" RPC to the Ra server. Therefore, it knows about Ra internals which is not great.