TSAN fixes: Refactor mutex handling#7744
Draft
eddyashton wants to merge 20 commits intomicrosoft:mainfrom
Draft
Conversation
…ion - become primary _during_ construction!
…g KV or consensus operations
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors node startup and consensus initialisation to reduce TSAN-reported deadlocks/races by making startup state explicit, adjusting lock usage around certificate/ledger-secret access, and deferring some potentially blocking work to async tasks.
Changes:
- Introduces
aft::Aft::StartupState/StartupRoleto initialise consensus as Primary/Backup (and optionally seed term/index/view history) inside the consensus constructor. - Splits certificate locking in
NodeStatevia a dedicatedendorsed_cert_lock, and switches several frontend openings toopen_frontend_asyncto avoid lock-order inversions. - Moves
LedgerSecretsmutex acquisition after KV dependency checks, and removes some TSAN suppressions.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
tsan_env_suppressions |
Removes deadlock/race suppressions which are presumed obsolete after lock refactors. |
src/node/node_state.h |
Adds dedicated cert lock, refactors consensus setup to accept startup state, and introduces async frontend opening to reduce lock contention. |
src/node/ledger_secrets.h |
Adjusts lock ordering by taking KV dependency before acquiring the ledger-secrets mutex. |
src/consensus/aft/raft.h |
Adds consensus constructor startup initialisation logic for primary/backup roles. |
src/node/node_state.h
Outdated
|
|
||
| accept_node_tls_connections(); | ||
| open_frontend(ActorsType::nodes); | ||
| open_frontend_async(ActorsType::nodes); |
Comment on lines
+3046
to
3049
| // Caller must ensure endorsed_cert_lock is held, or that the cert | ||
| // fields are stable (e.g. during single-threaded startup). | ||
| auto node_client = std::make_shared<HTTPNodeClient>( | ||
| rpc_map, node_sign_kp, self_signed_node_cert, endorsed_node_cert); |
achamayou
reviewed
Mar 17, 2026
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.
This is largely written by the robot, so I'll let the robot describe the changes:
This pull request introduces several improvements to node startup, certificate handling, and lock management in the consensus and node state code. The most significant changes include the addition of a structured startup state for consensus initialization, improved lock usage to prevent deadlocks, and asynchronous frontend opening to avoid lock contention. These changes enhance the robustness and clarity of node initialization and certificate management.
Consensus Startup Improvements:
StartupRoleandStartupStatestructs toaft::Raftfor explicit initialization as primary or backup, including state info such as index, term, and view history. The consensus constructor now uses this to set up initial state and role, supporting more flexible and safer node startup scenarios.setup_consensusinNodeStateto accept and propagateStartupState, enabling correct initialization for both primary and backup roles, and ensuring backup initialization runs before other threads access consensus.Certificate Locking and Management:
endorsed_cert_lockfor certificate fields inNodeState, replacing the main lock in certificate-related operations to avoid lock-order-inversion and potential deadlocks. Certificate accesses and updates now use this lock, and new helper methods for safe/unsafe certificate access were added.Frontend Initialization and Lock Avoidance:
open_frontend_async, scheduling frontend opening tasks to avoid holding KV or consensus locks during potentially blocking operations. This change applies to node, member, and user frontends.Ledger Secrets Locking Consistency:
ledger_secrets.hfunctions to after dependency checks, ensuring consistent lock ordering and reducing risk of deadlocks.Cleanup and Deadlock Suppression:
tsan_env_suppressions, reflecting improvements in lock handling and concurrency.