Skip to content

Commit 38860d3

Browse files
committed
Modify running_calls do not depends the thread for gRPC callback.
1 parent f4521f3 commit 38860d3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

exporters/otlp/src/otlp_grpc_client.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,12 @@ OtlpGrpcClient::~OtlpGrpcClient()
275275
#ifdef ENABLE_ASYNC_EXPORT
276276
if (async_data)
277277
{
278-
std::lock_guard<std::mutex> lock(async_data->running_calls_lock);
279-
for (auto &call_data : async_data->running_calls)
278+
std::unordered_set<std::shared_ptr<OtlpGrpcAsyncCallDataBase>> running_calls;
279+
{
280+
std::lock_guard<std::mutex> lock(async_data->running_calls_lock);
281+
running_calls = async_data->running_calls;
282+
}
283+
for (auto &call_data : running_calls)
280284
{
281285
if (call_data && call_data->grpc_context)
282286
{
@@ -663,8 +667,12 @@ bool OtlpGrpcClient::Shutdown(OtlpGrpcClientReferenceGuard &guard,
663667
{
664668
force_flush_result = ForceFlush(timeout);
665669

666-
std::lock_guard<std::mutex> lock(async_data_->running_calls_lock);
667-
for (auto &call_data : async_data_->running_calls)
670+
std::unordered_set<std::shared_ptr<OtlpGrpcAsyncCallDataBase>> running_calls;
671+
{
672+
std::lock_guard<std::mutex> lock(async_data_->running_calls_lock);
673+
running_calls = async_data_->running_calls;
674+
}
675+
for (auto &call_data : running_calls)
668676
{
669677
if (call_data && call_data->grpc_context)
670678
{

0 commit comments

Comments
 (0)