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.

(cherry picked from commit bitcoin/bitcoin@1c9394ad47)
This commit is contained in:
Matt Corallo 2018-02-06 13:32:53 -05:00 committed by Jack Grigg
parent 474aefcde6
commit 327807e05a
1 changed files with 9 additions and 2 deletions

View File

@ -1906,8 +1906,11 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
// Wait for genesis block to be processed
{
WaitableLock lock(cs_GenesisWait);
while (!fHaveGenesis) {
condvar_GenesisWait.wait(lock);
// We previously could hang here if StartShutdown() is called prior to
// ThreadImport getting started, so instead we just wait on a timer to
// check ShutdownRequested() regularly.
while (!fHaveGenesis && !ShutdownRequested()) {
condvar_GenesisWait.wait_for(lock, std::chrono::milliseconds(500));
}
uiInterface.NotifyBlockTip.disconnect(BlockNotifyGenesisWait);
}
@ -1915,6 +1918,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
return false;
}
if (ShutdownRequested()) {
return false;
}
// ********************************************************* Step 11: start node
if (!strErrors.str().empty())