v1.18: Fix BankForks::new_rw_arc memory leak (backport of #1893) #2065
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
BankForks::new_rw_arc
leaks memory becauseBankForks
holds anArc
to aBank
and theBank
holds anArc
toBankForks
through theBank::transaction_processor: TransactionBatchProcessor<BankForks>
,TransactionProcessor<FG: ForkGraph>::program_cache: Arc<RwLock<ProgramCache<FG>>>
,ProgramCache<FG: ForkGraph>::fork_graph: Option<Arc<RwLock<FG>>>
reference cycle.Summary of Changes
Changed the
fork_graph
field topub fork_graph: Option<Weak<RwLock<FG>>>
to break the reference cycle. Thetest_bank_forks_new_rw_arc_memory_leak
fails before the bug fix because of leaked threads from thread pools insideAccountsDb
.This bug has been introduced in solana-labs#33776. This bug affects also v1.18 and v1.17.
This is an automatic backport of pull request #1893 done by Mergify.