From 4e8b89007c28da4130dc643aea59f0f15efa590a Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sat, 4 Jan 2020 14:21:00 +0300 Subject: [PATCH] AppInitMain should quit early and return `false` if shutdown was requested at some point (#3267) This fixes crashes e.g. when user decided to shutdown while rescanning the wallet --- src/init.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index d390b454d9..fee15bcc8b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1964,6 +1964,14 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) LogPrintf("No wallet support compiled in!\n"); #endif + // As InitLoadWallet can take several minutes, it's possible the user + // requested to kill the GUI during the last operation. If so, exit. + if (fRequestShutdown) + { + LogPrintf("Shutdown requested. Exiting.\n"); + return false; + } + // ********************************************************* Step 9: data directory maintenance // if pruning, unset the service bit and perform the initial blockstore prune @@ -1977,6 +1985,14 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) } } + // As PruneAndFlush can take several minutes, it's possible the user + // requested to kill the GUI during the last operation. If so, exit. + if (fRequestShutdown) + { + LogPrintf("Shutdown requested. Exiting.\n"); + return false; + } + // ********************************************************* Step 10a: Prepare Masternode related stuff fMasternodeMode = false; std::string strMasterNodeBLSPrivKey = gArgs.GetArg("-masternodeblsprivkey", ""); @@ -2129,6 +2145,14 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) 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) + { + LogPrintf("Shutdown requested. Exiting.\n"); + return false; + } + // ********************************************************* Step 12: start node //// debug print @@ -2209,5 +2233,12 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) } #endif + // Final check if the user requested to kill the GUI during one of the last operations. If so, exit. + if (fRequestShutdown) + { + LogPrintf("Shutdown requested. Exiting.\n"); + return false; + } + return true; }