Skip to content

Commit

Permalink
Merge bitcoin#12367: Fix two fast-shutdown bugs
Browse files Browse the repository at this point in the history
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 bitcoin#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
  • Loading branch information
laanwj authored and PastaPastaPasta committed Mar 14, 2020
1 parent 5fd6510 commit a7bdf62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/init.cpp
Expand Up @@ -2191,16 +2191,18 @@ bool AppInitMain(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);
}

// As importing blocks can take several minutes, it's possible the user
// requested to kill the GUI during one of the last operations. If so, exit.
if (fRequestShutdown)
{
if (ShutdownRequested()) {
LogPrintf("Shutdown requested. Exiting.\n");
return false;
}
Expand Down
9 changes: 7 additions & 2 deletions src/validation.cpp
Expand Up @@ -2850,8 +2850,6 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
int nStopAtHeight = gArgs.GetArg("-stopatheight", DEFAULT_STOPATHEIGHT);
do {
boost::this_thread::interruption_point();
if (ShutdownRequested())
break;

const CBlockIndex *pindexFork;
bool fInitialDownload;
Expand Down Expand Up @@ -2899,6 +2897,13 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
}

if (nStopAtHeight && pindexNewTip && pindexNewTip->nHeight >= nStopAtHeight) StartShutdown();

// We check shutdown only after giving ActivateBestChainStep a chance to run once so that we
// never shutdown before connecting the genesis block during LoadChainTip(). Previously this
// caused an assert() failure during shutdown in such cases as the UTXO DB flushing checks
// that the best block hash is non-null.
if (ShutdownRequested())
break;
} while (pindexNewTip != pindexMostWork);
CheckBlockIndex(chainparams.GetConsensus());

Expand Down

0 comments on commit a7bdf62

Please sign in to comment.