mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-12 05:32:22 +02:00
Merge bitcoin/bitcoin#36148: test: Avoid unsafe memory race in index_reorg_crash shutdown
fab80e82c1test: Avoid unsafe memory race in baseindex_no_commit_ahead_of_flush (MarcoFalke)fa0f14ef5etest: Avoid unsafe memory race in index_reorg_crash shutdown (MarcoFalke)faf9c8e8a1test: Clarify index.GetSummary().synced state in index_reorg_crash (MarcoFalke) Pull request description: Currently, the `index_reorg_crash` test may rarely crash due to UB in sanitizers like TSan or ASan. This is perfectly fine, because it is just a rare test-only issue. However, fix it nonetheless by adding a missing drain of the unused in-flight events. Also, add a small check about the synced state while touching this test. ACKs for top commit: arejula27: ACKfab80e82c1furszy: ACKfab80e82c1Tree-SHA512: 4423e420421aa37d8b59e053f44c455fafb676102866bdf23988cf72f3d3f265b996bd953583ea8208f1534defb0e16b13ef08644be97e61959dc777a2918e5a
This commit is contained in:
@@ -84,6 +84,10 @@ BOOST_FIXTURE_TEST_CASE(baseindex_no_commit_ahead_of_flush, TestChain100Setup)
|
||||
// Reload index to see which block data was actually committed.
|
||||
BOOST_REQUIRE(index->Init());
|
||||
BOOST_CHECK_EQUAL(index->GetSummary().best_block_height, expected_commit_height);
|
||||
|
||||
// Drain in-flight validation callbacks before destroying the index.
|
||||
m_node.chain->context()->validation_signals->SyncWithValidationInterfaceQueue();
|
||||
// shutdown sequence (c.f. Shutdown() in init.cpp)
|
||||
index->Stop();
|
||||
};
|
||||
|
||||
@@ -223,10 +227,17 @@ BOOST_FIXTURE_TEST_CASE(index_reorg_crash, TestChain100Setup)
|
||||
BOOST_REQUIRE(m_node.chainman->ProcessNewBlock(block, /*force_processing=*/true, /*min_pow_checked=*/true, nullptr));
|
||||
}
|
||||
|
||||
// The index thread is blocked and not done
|
||||
BOOST_CHECK(!index.GetSummary().synced);
|
||||
|
||||
// Unblock the index thread so it can process the reorg
|
||||
promise.set_value();
|
||||
// Wait for the index to reach the new tip
|
||||
func_wait_until(blocking_height + 2, 5s);
|
||||
|
||||
// Drain unused BlockConnected events, to avoid unsafe memory races during destruction
|
||||
m_node.chain->context()->validation_signals->SyncWithValidationInterfaceQueue();
|
||||
// shutdown sequence (c.f. Shutdown() in init.cpp)
|
||||
index.Stop();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user