From e95835387c41b53ac984debf61ca2f281ca68505 Mon Sep 17 00:00:00 2001 From: Santiago Gimeno Date: Mon, 18 Nov 2024 18:54:18 +0100 Subject: [PATCH] agents: fix synchronized code in GrpcAgent It should also cover the `start_profiling` fn execution. PR-URL: https://github.com/nodesource/nsolid/pull/222 Reviewed-By: Trevor Norris --- agents/grpc/src/grpc_agent.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/agents/grpc/src/grpc_agent.cc b/agents/grpc/src/grpc_agent.cc index f47b64b9e8..a47b03f0fb 100644 --- a/agents/grpc/src/grpc_agent.cc +++ b/agents/grpc/src/grpc_agent.cc @@ -1823,23 +1823,24 @@ ErrorType GrpcAgent::do_start_prof_init( opt.metadata_pb = std::move(args.metadata()); }, options); - ErrorType error = (this->*start_profiling)(args, options); - if (error != ErrorType::ESuccess) { - return error; - } - nsuv::ns_mutex::scoped_lock lock(profile_state_lock_); ProfileState& profile_state = profile_state_[type]; ProfileStor stor{ req.requestid(), uv_now(&loop_), nullptr, - std::move(options) }; + options }; auto iter = profile_state.pending_profiles_map.emplace(thread_id, std::move(stor)); if (iter.second == false) { return ErrorType::EInProgressError; } + ErrorType error = (this->*start_profiling)(args, options); + if (error != ErrorType::ESuccess) { + profile_state.pending_profiles_map.erase(iter.first); + return error; + } + if (type != kHeapSnapshot) { profile_state.nr_profiles++; }