File tree Expand file tree Collapse file tree 3 files changed +19
-7
lines changed
include/opentelemetry/exporters/otlp Expand file tree Collapse file tree 3 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -275,7 +275,7 @@ class OtlpHttpClient
275
275
std::shared_ptr<ext::http::client::HttpClient> http_client);
276
276
277
277
// Stores if this HTTP client had its Shutdown() method called
278
- bool is_shutdown_;
278
+ std::atomic< bool > is_shutdown_;
279
279
280
280
// The configuration options associated with this HTTP client.
281
281
const OtlpHttpClientOptions options_;
Original file line number Diff line number Diff line change @@ -567,14 +567,21 @@ bool OtlpGrpcClient::Shutdown(std::chrono::microseconds timeout) noexcept
567
567
return true ;
568
568
}
569
569
570
+ bool force_flush_result;
570
571
if (false == is_shutdown_.exchange (true , std::memory_order_acq_rel))
571
572
{
572
573
is_shutdown_ = true ;
573
574
575
+ force_flush_result = ForceFlush (timeout);
576
+
574
577
async_data_->cq .Shutdown ();
575
578
}
579
+ else
580
+ {
581
+ force_flush_result = ForceFlush (timeout);
582
+ }
576
583
577
- return ForceFlush (timeout) ;
584
+ return force_flush_result ;
578
585
}
579
586
580
587
#endif
Original file line number Diff line number Diff line change 2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
4
#include " opentelemetry/exporters/otlp/otlp_http_client.h"
5
+ #include < chrono>
5
6
6
7
#if defined(HAVE_GSL)
7
8
# include < gsl/gsl>
@@ -819,19 +820,23 @@ bool OtlpHttpClient::ForceFlush(std::chrono::microseconds timeout) noexcept
819
820
820
821
bool OtlpHttpClient::Shutdown (std::chrono::microseconds timeout) noexcept
821
822
{
823
+ is_shutdown_.store (true , std::memory_order_release);
824
+
825
+ ForceFlush (timeout);
826
+
822
827
{
823
828
std::lock_guard<std::recursive_mutex> guard{session_manager_lock_};
824
- is_shutdown_ = true ;
825
829
826
830
// Shutdown the session manager
827
831
http_client_->CancelAllSessions ();
828
832
http_client_->FinishAllSessions ();
829
833
}
830
834
831
- ForceFlush (timeout);
832
-
835
+ // Wait util all sessions are canceled.
833
836
while (cleanupGCSessions ())
834
- ;
837
+ {
838
+ ForceFlush (std::chrono::milliseconds{1 });
839
+ }
835
840
return true ;
836
841
}
837
842
@@ -1017,7 +1022,7 @@ bool OtlpHttpClient::cleanupGCSessions() noexcept
1017
1022
1018
1023
bool OtlpHttpClient::IsShutdown () const noexcept
1019
1024
{
1020
- return is_shutdown_;
1025
+ return is_shutdown_. load (std::memory_order_acquire) ;
1021
1026
}
1022
1027
1023
1028
} // namespace otlp
You can’t perform that action at this time.
0 commit comments