This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
runtime: fix possible deadlock in accounts_db #10469
Merged
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.
Problem
Similar to #10466
In runtime/src/accounts_db.rs:
storage
is beforeaccounts_index
ingenerate_index()
solana/runtime/src/accounts_db.rs
Lines 1808 to 1812 in 4cfb758
However, the lock order conflicts with any other place involving the two locks, e.g.
solana/runtime/src/accounts_db.rs
Lines 662 to 667 in 4cfb758
The fix is to swap the order of the two locks.
The first read lock is in
generate_index()
solana/runtime/src/accounts_db.rs
Lines 1808 to 1809 in 4cfb758
Then
scan_account_storage()
is called at L1823solana/runtime/src/accounts_db.rs
Line 1823 in 4cfb758
The second lock is at L969
solana/runtime/src/accounts_db.rs
Lines 967 to 969 in 4cfb758
The fix is to use a lock propagation way to avoid recursively acquiring the same lock.
Separate the lock acquisition from
scan_account_storage
and pass the ref to read lock guard into the newscan_account_storage_inner
.There remains one possible double read lock that I find really tricky to tackle.
In ledger/src/blockstore.rs:
get_confirmed_block()
:solana/ledger/src/blockstore.rs
Line 1501 in 4cfb758
get_slot_entries()
is called:solana/ledger/src/blockstore.rs
Line 1518 in 4cfb758
solana/ledger/src/blockstore.rs
Lines 1524 to 1525 in 4cfb758
get_slot_entries_with_shred_info()
:solana/ledger/src/blockstore.rs
Lines 1866 to 1867 in 4cfb758
get_completed_ranges()
:solana/ledger/src/blockstore.rs
Line 1883 in 4cfb758
solana/ledger/src/blockstore.rs
Line 1915 in 4cfb758
Summary of Changes
storage
andaccounts_index
ingenerate_index()
.scan_account_storage
to separate the lock acquisition.