Skip to content

Commit ee830ee

Browse files
crowning-schinzelh
authored andcommitted
Merge #822: [Core]: fix restart hanging during wallet-repair
37a934c [Core]: fix restart hanging during wallet-repair
1 parent 3d2bc6a commit ee830ee

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/httpserver.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ class WorkQueue
152152
void WaitExit()
153153
{
154154
boost::unique_lock<boost::mutex> lock(cs);
155-
while (numThreads > 0)
155+
while (numThreads > 0){
156156
cond.wait(lock);
157+
}
157158
}
158159

159160
/** Return current depth of queue */
@@ -476,7 +477,12 @@ void StopHTTPServer()
476477
LogPrint("http", "Stopping HTTP server\n");
477478
if (workQueue) {
478479
LogPrint("http", "Waiting for HTTP worker threads to exit\n");
480+
#ifndef WIN32
481+
// ToDo: Disabling WaitExit() for Windows platforms is an ugly workaround for the wallet not
482+
// closing during a repair-restart. It doesn't hurt, though, because threadHTTP.timed_join
483+
// below takes care of this and sends a loopbreak.
479484
workQueue->WaitExit();
485+
#endif
480486
delete workQueue;
481487
}
482488
if (eventBase) {
@@ -492,6 +498,7 @@ void StopHTTPServer()
492498
#else
493499
if (!threadHTTP.timed_join(boost::posix_time::milliseconds(2000))) {
494500
#endif
501+
495502
LogPrintf("HTTP event loop did not exit within allotted time, sending loopbreak\n");
496503
event_base_loopbreak(eventBase);
497504
threadHTTP.join();

src/init.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ void PrepareShutdown()
205205
/// module was initialized.
206206
RenameThread("dash-shutoff");
207207
mempool.AddTransactionsUpdated(1);
208-
209208
StopHTTPRPC();
210209
StopREST();
211210
StopRPC();
@@ -218,15 +217,13 @@ void PrepareShutdown()
218217
StopNode();
219218

220219
// STORE DATA CACHES INTO SERIALIZED DAT FILES
221-
222220
CFlatDB<CMasternodeMan> flatdb1("mncache.dat", "magicMasternodeCache");
223221
flatdb1.Dump(mnodeman);
224222
CFlatDB<CMasternodePayments> flatdb2("mnpayments.dat", "magicMasternodePaymentsCache");
225223
flatdb2.Dump(mnpayments);
226224
CFlatDB<CGovernanceManager> flatdb3("governance.dat", "magicGovernanceCache");
227225
flatdb3.Dump(governance);
228226

229-
StopTorControl();
230227
UnregisterNodeSignals(GetNodeSignals());
231228

232229
if (fFeeEstimatesInitialized)
@@ -298,8 +295,8 @@ void Shutdown()
298295
if(!fRestartRequested){
299296
PrepareShutdown();
300297
}
301-
302-
// Shutdown part 2: delete wallet instance
298+
// Shutdown part 2: Stop TOR thread and delete wallet instance
299+
StopTorControl();
303300
#ifdef ENABLE_WALLET
304301
delete pwalletMain;
305302
pwalletMain = NULL;

src/torcontrol.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,15 @@ void InterruptTorControl()
687687

688688
void StopTorControl()
689689
{
690+
// timed_join() avoids the wallet not closing during a repair-restart. For a 'normal' wallet exit
691+
// it behaves for our cases exactly like the normal join()
690692
if (base) {
691-
torControlThread.join();
693+
#if BOOST_VERSION >= 105000
694+
torControlThread.try_join_for(boost::chrono::seconds(1));
695+
#else
696+
torControlThread.timed_join(boost::posix_time::seconds(1));
697+
#endif
692698
event_base_free(base);
693699
base = 0;
694700
}
695701
}
696-

0 commit comments

Comments
 (0)