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.");