From ed34832c0117c88e3c442e75d1f7d038072c7809 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Tue, 13 Feb 2018 00:24:14 -0500 Subject: [PATCH 1/2] fix possible shutdown assertion with -reindex-shutdown Credit @eklitzke for reproducing. --- src/validation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validation.cpp b/src/validation.cpp index a1c57fa9d3b9f..84ce1a60e6341 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1776,7 +1776,7 @@ bool static FlushStateToDisk(CValidationState& state, FlushStateMode mode) } // Flush best chain related state. This can only be done if the blocks / block index write was also done. - if (fDoFullFlush) { + if (fDoFullFlush && !pcoinsTip->GetBestBlock().IsNull()) { // Typical Coin structures on disk are around 48 bytes in size. // Pushing a new one to the database can cause it to be written // twice (once in the log, and once in the tables). This is already From 0360cad520d3af2c5a6d171b565011e79cf3a7e9 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 6 Feb 2018 13:32:53 -0500 Subject: [PATCH 2/2] 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. --- src/init.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index cc976b8285581..e1c4da10f8373 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1710,12 +1710,19 @@ bool AppInitMain() LogPrintf("Waiting for genesis block to be imported...\n"); { std::unique_lock lockG(cs_GenesisWait); - while (!fHaveGenesis) { - condvar_GenesisWait.wait(lockG); + // 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(lockG, std::chrono::milliseconds(500)); } uiInterface.NotifyBlockTip.disconnect(BlockNotifyGenesisWait); } + if (ShutdownRequested()) { + return false; + } + int chain_active_height; //// debug print