Skip to content

Commit 7217ea2

Browse files
committed
Merge #12367: Fix two fast-shutdown bugs
dd2de47 Fix fast-shutdown crash if genesis block was not loaded (Matt Corallo) 1c9394a Fix fast-shutdown hang on ThreadImport+GenesisWait (Matt Corallo) Pull request description: The second commit is a much simpler alternative fix for the issue fixed in #12349. To test I made ShutdownRequested() always StartShutdown() after a certain number of calls, which turned up one other hang, fixed in the first commit. Tree-SHA512: 86bde6ac4b8b4e2cb99fff87dafeed02c0d9514acee6d94455637fb2da9ffc274b5ad31b0a6b9f5bd7b700ae35395f28ddb14ffc65ddda3619aa28df28a5607d
2 parents 0277173 + dd2de47 commit 7217ea2

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/init.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,12 +1645,19 @@ bool AppInitMain()
16451645
// Wait for genesis block to be processed
16461646
{
16471647
WaitableLock lock(cs_GenesisWait);
1648-
while (!fHaveGenesis) {
1649-
condvar_GenesisWait.wait(lock);
1648+
// We previously could hang here if StartShutdown() is called prior to
1649+
// ThreadImport getting started, so instead we just wait on a timer to
1650+
// check ShutdownRequested() regularly.
1651+
while (!fHaveGenesis && !ShutdownRequested()) {
1652+
condvar_GenesisWait.wait_for(lock, std::chrono::milliseconds(500));
16501653
}
16511654
uiInterface.NotifyBlockTip.disconnect(BlockNotifyGenesisWait);
16521655
}
16531656

1657+
if (ShutdownRequested()) {
1658+
return false;
1659+
}
1660+
16541661
// ********************************************************* Step 11: start node
16551662

16561663
int chain_active_height;

src/validation.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,9 +2581,6 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
25812581
SyncWithValidationInterfaceQueue();
25822582
}
25832583

2584-
if (ShutdownRequested())
2585-
break;
2586-
25872584
const CBlockIndex *pindexFork;
25882585
bool fInitialDownload;
25892586
{
@@ -2630,6 +2627,13 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
26302627
}
26312628

26322629
if (nStopAtHeight && pindexNewTip && pindexNewTip->nHeight >= nStopAtHeight) StartShutdown();
2630+
2631+
// We check shutdown only after giving ActivateBestChainStep a chance to run once so that we
2632+
// never shutdown before connecting the genesis block during LoadChainTip(). Previously this
2633+
// caused an assert() failure during shutdown in such cases as the UTXO DB flushing checks
2634+
// that the best block hash is non-null.
2635+
if (ShutdownRequested())
2636+
break;
26332637
} while (pindexNewTip != pindexMostWork);
26342638
CheckBlockIndex(chainparams.GetConsensus());
26352639

0 commit comments

Comments
 (0)