aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoão Barbosa <joao.paulo.barbosa@gmail.com>2020-04-29 10:40:39 +0100
committerfanquake <fanquake@gmail.com>2020-05-15 07:42:07 +0800
commitca4dac48c5675af3fc53db6740a0b70fef622b0a (patch)
treea6a0fcbc280a075c5f8ddea6f8e7969cf43d98ce
parenta3fe458a1e477cacd19e7e0edb8e7bb965067115 (diff)
downloadbitcoin-ca4dac48c5675af3fc53db6740a0b70fef622b0a.tar.xz
rpc: Add mutex to guard deadlineTimers
Github-Pull: #18814 Rebased-From: a2e6db5c4f1bb52a8814102b628e51652493d06a
-rw-r--r--src/rpc/server.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp
index e2618c16da..219979f095 100644
--- a/src/rpc/server.cpp
+++ b/src/rpc/server.cpp
@@ -25,7 +25,8 @@ static std::string rpcWarmupStatus GUARDED_BY(cs_rpcWarmup) = "RPC server starte
/* Timer-creating functions */
static RPCTimerInterface* timerInterface = nullptr;
/* Map of name to timer. */
-static std::map<std::string, std::unique_ptr<RPCTimerBase> > deadlineTimers;
+static Mutex g_deadline_timers_mutex;
+static std::map<std::string, std::unique_ptr<RPCTimerBase> > deadlineTimers GUARDED_BY(g_deadline_timers_mutex);
static bool ExecuteCommand(const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler);
struct RPCCommandExecutionInfo
@@ -298,7 +299,7 @@ void InterruptRPC()
void StopRPC()
{
LogPrint(BCLog::RPC, "Stopping RPC\n");
- deadlineTimers.clear();
+ WITH_LOCK(g_deadline_timers_mutex, deadlineTimers.clear());
DeleteAuthCookie();
g_rpcSignals.Stopped();
}
@@ -486,6 +487,7 @@ void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nS
{
if (!timerInterface)
throw JSONRPCError(RPC_INTERNAL_ERROR, "No timer handler registered for RPC");
+ LOCK(g_deadline_timers_mutex);
deadlineTimers.erase(name);
LogPrint(BCLog::RPC, "queue run of timer %s in %i seconds (using %s)\n", name, nSeconds, timerInterface->Name());
deadlineTimers.emplace(name, std::unique_ptr<RPCTimerBase>(timerInterface->NewTimer(func, nSeconds*1000)));