Fix data race on peer config_ in handle_rpc_result - #119
Merged
Conversation
The `peer::config_` member is protected by `config_mutex_` and is meant to be read only through the locked accessors (`get_id`, `get_endpoint`, `get_config`, ...). Several call sites in `peer.cxx` still read `config_->get_id` directly, bypassing the mutex. ThreadSanitizer reports a data race between the unlocked read of `srv_config::get_id` in `peer::handle_rpc_result` (an asio RPC worker thread) and the construction of a fresh `srv_config` that is published via `peer::set_config` while `cluster_config::deserialize` runs inside `raft_server::commit_conf` on the commit thread. The lock on `config_mutex_` is the intended synchronization point, so the unlocked read leaves no happens-before edge. Route all of these reads through the locked `get_id` accessor, matching the earlier fix in commit 7a9de82 ("Fix some non dangerous races").
alexey-milovidov
added a commit
to ClickHouse/ClickHouse
that referenced
this pull request
Jun 14, 2026
NuRaft PR #119 has been merged. Move the submodule pointer from the fix commit to the fork's `master` tip (the merge commit), so it tracks master rather than a feature branch. ClickHouse/NuRaft#119 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
The
peer::config_member is protected byconfig_mutex_and is meant to be read only through the locked accessors (get_id,get_endpoint,get_config, ...). Several call sites inpeer.cxxstill readconfig_->get_iddirectly, bypassing the mutex.ThreadSanitizer reports a data race between the unlocked read of
srv_config::get_idinpeer::handle_rpc_result(an asio RPC worker thread) and the construction of a freshsrv_configthat is published viapeer::set_configwhilecluster_config::deserializeruns insideraft_server::commit_confon the commit thread. The lock onconfig_mutex_is the intended synchronization point, so the unlocked read leaves no happens-before edge.Route all of these reads through the locked
get_idaccessor, matching the earlier fix in commit 7a9de82 ("Fix some non dangerous races").Found by the ClickHouse
amd_tsanintegration testtest_keeper_4lw_reconfiguration::test_precondition_failure.