Skip to content

TSAN fixes: Refactor mutex handling#7744

Draft
eddyashton wants to merge 20 commits intomicrosoft:mainfrom
eddyashton:tsan_turmoil
Draft

TSAN fixes: Refactor mutex handling#7744
eddyashton wants to merge 20 commits intomicrosoft:mainfrom
eddyashton:tsan_turmoil

Conversation

@eddyashton
Copy link
Member

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:

  • Added StartupRole and StartupState structs to aft::Raft for 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.
  • Modified setup_consensus in NodeState to accept and propagate StartupState, enabling correct initialization for both primary and backup roles, and ensuring backup initialization runs before other threads access consensus.

Certificate Locking and Management:

  • Introduced a dedicated endorsed_cert_lock for certificate fields in NodeState, 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:

  • Replaced synchronous frontend opening with 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:

  • Moved mutex locking in ledger_secrets.h functions to after dependency checks, ensuring consistent lock ordering and reducing risk of deadlocks.

Cleanup and Deadlock Suppression:

  • Removed deadlock and race suppressions for files no longer requiring them in tsan_env_suppressions, reflecting improvements in lock handling and concurrency.

@eddyashton eddyashton requested a review from a team as a code owner March 17, 2026 14:26
Copilot AI review requested due to automatic review settings March 17, 2026 14:26
@eddyashton eddyashton added the run-long-test Run Long Test job label Mar 17, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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/StartupRole to initialise consensus as Primary/Backup (and optionally seed term/index/view history) inside the consensus constructor.
  • Splits certificate locking in NodeState via a dedicated endorsed_cert_lock, and switches several frontend openings to open_frontend_async to avoid lock-order inversions.
  • Moves LedgerSecrets mutex 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.


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);
@eddyashton eddyashton marked this pull request as draft March 17, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-long-test Run Long Test job

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants