From 77cd761ea455a52a345bb368bf710445e3f48f28 Mon Sep 17 00:00:00 2001 From: jouzo Date: Wed, 18 May 2022 20:11:03 +0100 Subject: [PATCH] Add CLockFreeGuard before get method --- src/rpc/stats.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rpc/stats.cpp b/src/rpc/stats.cpp index c79ef754649..e8df5e1226d 100644 --- a/src/rpc/stats.cpp +++ b/src/rpc/stats.cpp @@ -75,6 +75,7 @@ RPCStats RPCStats::fromJSON(UniValue json) { void CRPCStats::add(const std::string& name, const int64_t latency, const int64_t payload) { + CLockFreeGuard lock(lock_stats); auto stats = CRPCStats::get(name); if (stats) { stats->count++; @@ -93,8 +94,6 @@ void CRPCStats::add(const std::string& name, const int64_t latency, const int64_ stats = { name, latency, payload }; } stats->history.push_back({ stats->lastUsedTime, latency, payload }); - - CLockFreeGuard lock(lock_stats); map[name] = *stats; } @@ -143,6 +142,9 @@ static UniValue getrpcstats(const JSONRPCRequest& request) } auto command = request.params[0].get_str(); + + CLockFreeGuard lock(lock_stats); + auto stats = statsRPC.get(command); if (!stats) { throw JSONRPCError(RPC_INVALID_PARAMS, "No stats for this command.");