Skip to content

Commit

Permalink
Fix session lock of OtlpHttpClient (#1760)
Browse files Browse the repository at this point in the history
  • Loading branch information
owent authored Nov 22, 2022
1 parent 8f778b7 commit 6644ddd
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions exporters/otlp/src/otlp_http_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -981,16 +981,19 @@ void OtlpHttpClient::addSession(HttpSessionData &&session_data) noexcept
return;
}

opentelemetry::ext::http::client::Session *key = session_data.session.get();
ResponseHandler *handle = static_cast<ResponseHandler *>(session_data.event_handle.get());

handle->Bind(this, *key);
std::shared_ptr<opentelemetry::ext::http::client::Session> session = session_data.session;
std::shared_ptr<opentelemetry::ext::http::client::EventHandler> handle =
session_data.event_handle;
{
std::lock_guard<std::recursive_mutex> guard{session_manager_lock_};
static_cast<ResponseHandler *>(handle.get())->Bind(this, *session);

HttpSessionData &store_session_data = running_sessions_[key];
store_session_data = std::move(session_data);
HttpSessionData &store_session_data = running_sessions_[session.get()];
store_session_data = std::move(session_data);
}

// Send request after the session is added
key->SendRequest(store_session_data.event_handle);
session->SendRequest(handle);
}

bool OtlpHttpClient::cleanupGCSessions() noexcept
Expand Down

0 comments on commit 6644ddd

Please sign in to comment.