aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2018-02-08 08:40:55 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2018-02-08 08:41:18 +0100
commit7217ea2cc8dd17784a95574724e76303ac2e2823 (patch)
tree0436ac31a688ecb1b59660a5e02abc1473bd06b6 /src
parent0277173b1defb63216d40a8d8805ae6d5d563c26 (diff)
parentdd2de47c6288654abb2c3eef29edcd1cc5f39fc9 (diff)
downloadbitcoin-7217ea2cc8dd17784a95574724e76303ac2e2823.tar.xz
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
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp11
-rw-r--r--src/validation.cpp10
2 files changed, 16 insertions, 5 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 50643ff96b..14dd8fc8ac 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1645,12 +1645,19 @@ bool AppInitMain()
// 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);
}
+ if (ShutdownRequested()) {
+ return false;
+ }
+
// ********************************************************* Step 11: start node
int chain_active_height;
diff --git a/src/validation.cpp b/src/validation.cpp
index 16b656c7f5..f1abe6f46d 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -2581,9 +2581,6 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
SyncWithValidationInterfaceQueue();
}
- if (ShutdownRequested())
- break;
-
const CBlockIndex *pindexFork;
bool fInitialDownload;
{
@@ -2630,6 +2627,13 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
}
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());