Skip to content

Commit 09fc859

Browse files
TheBlueMattlaanwj
authored andcommitted
Fix fast-shutdown hang on ThreadImport+GenesisWait
If the user somehow manages to get into ShutdownRequested before ThreadImport gets to ActivateBestChain() we may hang waiting on condvar_GenesisWait forever. A simple wait_for and ShutdownRequested resolves this case. Github-Pull: #12367 Rebased-From: 1c9394a Tree-SHA512: fb0751ef32d2005520738bf3b0a0f41ae3f9314d700d2a85eb50f023e87e109ce806cdcdf4a08f49a4d9c1001e27df7f461d3fd52b1f5a57885260ce9375260f
1 parent da84760 commit 09fc859

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
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;

0 commit comments

Comments
 (0)