@@ -25,7 +25,8 @@ static std::string rpcWarmupStatus GUARDED_BY(cs_rpcWarmup) = "RPC server starte
25
25
/* Timer-creating functions */
26
26
static RPCTimerInterface* timerInterface = nullptr ;
27
27
/* Map of name to timer. */
28
- static std::map<std::string, std::unique_ptr<RPCTimerBase> > deadlineTimers;
28
+ static Mutex g_deadline_timers_mutex;
29
+ static std::map<std::string, std::unique_ptr<RPCTimerBase> > deadlineTimers GUARDED_BY (g_deadline_timers_mutex);
29
30
static bool ExecuteCommand (const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler);
30
31
31
32
struct RPCCommandExecutionInfo
@@ -298,7 +299,7 @@ void InterruptRPC()
298
299
void StopRPC ()
299
300
{
300
301
LogPrint (BCLog::RPC, " Stopping RPC\n " );
301
- deadlineTimers.clear ();
302
+ WITH_LOCK (g_deadline_timers_mutex, deadlineTimers.clear () );
302
303
DeleteAuthCookie ();
303
304
g_rpcSignals.Stopped ();
304
305
}
@@ -486,6 +487,7 @@ void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nS
486
487
{
487
488
if (!timerInterface)
488
489
throw JSONRPCError (RPC_INTERNAL_ERROR, " No timer handler registered for RPC" );
490
+ LOCK (g_deadline_timers_mutex);
489
491
deadlineTimers.erase (name);
490
492
LogPrint (BCLog::RPC, " queue run of timer %s in %i seconds (using %s)\n " , name, nSeconds, timerInterface->Name ());
491
493
deadlineTimers.emplace (name, std::unique_ptr<RPCTimerBase>(timerInterface->NewTimer (func, nSeconds*1000 )));
0 commit comments