diff --git a/ext/src/http/client/curl/http_client_curl.cc b/ext/src/http/client/curl/http_client_curl.cc index c4f26a0dea..a3445ea5bb 100644 --- a/ext/src/http/client/curl/http_client_curl.cc +++ b/ext/src/http/client/curl/http_client_curl.cc @@ -462,6 +462,11 @@ void HttpClient::MaybeSpawnBackgroundThread() { if (self->background_thread_) { + if (self->background_thread_instrumentation_ != nullptr) + { + self->background_thread_instrumentation_->OnEnd(); + self->background_thread_instrumentation_.reset(); + } self->background_thread_->detach(); self->background_thread_.reset(); } @@ -469,11 +474,6 @@ void HttpClient::MaybeSpawnBackgroundThread() } } } - - if (self->background_thread_instrumentation_ != nullptr) - { - self->background_thread_instrumentation_->OnEnd(); - } }, this)); }