Skip to content

Commit a2e6db5

Browse files
committed
rpc: Add mutex to guard deadlineTimers
1 parent 0ef0d33 commit a2e6db5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/rpc/server.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ static std::string rpcWarmupStatus GUARDED_BY(cs_rpcWarmup) = "RPC server starte
2525
/* Timer-creating functions */
2626
static RPCTimerInterface* timerInterface = nullptr;
2727
/* 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);
2930
static bool ExecuteCommand(const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler);
3031

3132
struct RPCCommandExecutionInfo
@@ -298,7 +299,7 @@ void InterruptRPC()
298299
void StopRPC()
299300
{
300301
LogPrint(BCLog::RPC, "Stopping RPC\n");
301-
deadlineTimers.clear();
302+
WITH_LOCK(g_deadline_timers_mutex, deadlineTimers.clear());
302303
DeleteAuthCookie();
303304
g_rpcSignals.Stopped();
304305
}
@@ -486,6 +487,7 @@ void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nS
486487
{
487488
if (!timerInterface)
488489
throw JSONRPCError(RPC_INTERNAL_ERROR, "No timer handler registered for RPC");
490+
LOCK(g_deadline_timers_mutex);
489491
deadlineTimers.erase(name);
490492
LogPrint(BCLog::RPC, "queue run of timer %s in %i seconds (using %s)\n", name, nSeconds, timerInterface->Name());
491493
deadlineTimers.emplace(name, std::unique_ptr<RPCTimerBase>(timerInterface->NewTimer(func, nSeconds*1000)));

0 commit comments

Comments
 (0)