Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ class WorkQueue
void WaitExit()
{
boost::unique_lock<boost::mutex> lock(cs);
while (numThreads > 0)
while (numThreads > 0){
cond.wait(lock);
}
}

/** Return current depth of queue */
Expand Down Expand Up @@ -476,7 +477,12 @@ void StopHTTPServer()
LogPrint("http", "Stopping HTTP server\n");
if (workQueue) {
LogPrint("http", "Waiting for HTTP worker threads to exit\n");
#ifndef WIN32
// ToDo: Disabling WaitExit() for Windows platforms is an ugly workaround for the wallet not
// closing during a repair-restart. It doesn't hurt, though, because threadHTTP.timed_join
// below takes care of this and sends a loopbreak.
workQueue->WaitExit();
#endif
delete workQueue;
}
if (eventBase) {
Expand All @@ -492,6 +498,7 @@ void StopHTTPServer()
#else
if (!threadHTTP.timed_join(boost::posix_time::milliseconds(2000))) {
#endif

LogPrintf("HTTP event loop did not exit within allotted time, sending loopbreak\n");
event_base_loopbreak(eventBase);
threadHTTP.join();
Expand Down
7 changes: 2 additions & 5 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ void PrepareShutdown()
/// module was initialized.
RenameThread("dash-shutoff");
mempool.AddTransactionsUpdated(1);

StopHTTPRPC();
StopREST();
StopRPC();
Expand All @@ -222,15 +221,13 @@ void PrepareShutdown()
StopNode();

// STORE DATA CACHES INTO SERIALIZED DAT FILES

CFlatDB<CMasternodeMan> flatdb1("mncache.dat", "magicMasternodeCache");
flatdb1.Dump(mnodeman);
CFlatDB<CMasternodePayments> flatdb2("mnpayments.dat", "magicMasternodePaymentsCache");
flatdb2.Dump(mnpayments);
CFlatDB<CGovernanceManager> flatdb3("governance.dat", "magicGovernanceCache");
flatdb3.Dump(governance);

StopTorControl();
UnregisterNodeSignals(GetNodeSignals());

if (fFeeEstimatesInitialized)
Expand Down Expand Up @@ -302,8 +299,8 @@ void Shutdown()
if(!fRestartRequested){
PrepareShutdown();
}

// Shutdown part 2: delete wallet instance
// Shutdown part 2: Stop TOR thread and delete wallet instance
StopTorControl();
#ifdef ENABLE_WALLET
delete pwalletMain;
pwalletMain = NULL;
Expand Down
9 changes: 7 additions & 2 deletions src/torcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,15 @@ void InterruptTorControl()

void StopTorControl()
{
// timed_join() avoids the wallet not closing during a repair-restart. For a 'normal' wallet exit
// it behaves for our cases exactly like the normal join()
if (base) {
torControlThread.join();
#if BOOST_VERSION >= 105000
torControlThread.try_join_for(boost::chrono::seconds(1));
#else
torControlThread.timed_join(boost::posix_time::seconds(1));
#endif
event_base_free(base);
base = 0;
}
}