File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change 3030#include < interfaces/handler.h>
3131#include < interfaces/node.h>
3232#include < noui.h>
33+ #include < rpc/server.h>
3334#include < ui_interface.h>
3435#include < uint256.h>
3536#include < util/system.h>
@@ -311,6 +312,11 @@ void BitcoinApplication::requestShutdown()
311312 // Request node shutdown, which can interrupt long operations, like
312313 // rescanning a wallet.
313314 m_node.startShutdown ();
315+ // Stop RPC for clean shutdown if waitfor* commands are executed.
316+ if (gArgs .GetBoolArg (" -server" , false )) {
317+ InterruptRPC ();
318+ StopRPC ();
319+ }
314320 // Unsetting the client model can cause the current thread to wait for node
315321 // to complete an operation, like wait for a RPC execution to complete.
316322 window->setClientModel (nullptr );
Original file line number Diff line number Diff line change 1515#include < boost/algorithm/string/classification.hpp>
1616#include < boost/algorithm/string/split.hpp>
1717
18+ #include < cassert>
1819#include < memory> // for unique_ptr
1920#include < unordered_map>
2021
2122static RecursiveMutex cs_rpcWarmup;
2223static std::atomic<bool > g_rpc_running{false };
24+ static std::atomic<bool > g_rpc_stopped{true };
2325static bool fRPCInWarmup GUARDED_BY (cs_rpcWarmup) = true;
2426static std::string rpcWarmupStatus GUARDED_BY (cs_rpcWarmup) = "RPC server started";
2527/* Timer-creating functions */
@@ -285,21 +287,28 @@ void StartRPC()
285287{
286288 LogPrint (BCLog::RPC, " Starting RPC\n " );
287289 g_rpc_running = true ;
290+ g_rpc_stopped = false ;
288291 g_rpcSignals.Started ();
289292}
290293
291294void InterruptRPC ()
292295{
296+ // This function could be called twice if the GUI has been started with -server=1.
297+ if (!g_rpc_running) return ;
293298 LogPrint (BCLog::RPC, " Interrupting RPC\n " );
294299 // Interrupt e.g. running longpolls
295300 g_rpc_running = false ;
296301}
297302
298303void StopRPC ()
299304{
305+ // This function could be called twice if the GUI has been started with -server=1.
306+ assert (!g_rpc_running);
307+ if (g_rpc_stopped) return ;
300308 LogPrint (BCLog::RPC, " Stopping RPC\n " );
301309 deadlineTimers.clear ();
302310 DeleteAuthCookie ();
311+ g_rpc_stopped = true ;
303312 g_rpcSignals.Stopped ();
304313}
305314
You can’t perform that action at this time.
0 commit comments