Skip to content

Commit 1c9394a

Browse files
committed
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.
1 parent 1462bde commit 1c9394a

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)