File tree 3 files changed +23
-8
lines changed
3 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -668,8 +668,12 @@ OtlpHttpClient::~OtlpHttpClient()
668
668
}
669
669
}
670
670
// When changes of running_sessions_ and notify_one/notify_all happen between predicate
671
- // checking and waiting, we should not wait forever.
672
- session_waker_.wait_for (lock, options_.timeout );
671
+ // checking and waiting, we should not wait forever. We should cleanup gc sessions here as soon
672
+ // as possible to call FinishSession() and cleanup resources.
673
+ if (std::cv_status::timeout == session_waker_.wait_for (lock, options_.timeout ))
674
+ {
675
+ cleanupGCSessions ();
676
+ }
673
677
}
674
678
675
679
// And then remove all session datas
@@ -781,8 +785,12 @@ bool OtlpHttpClient::ForceFlush(std::chrono::microseconds timeout) noexcept
781
785
}
782
786
}
783
787
// When changes of running_sessions_ and notify_one/notify_all happen between predicate
784
- // checking and waiting, we should not wait forever.
785
- session_waker_.wait_for (lock, options_.timeout );
788
+ // checking and waiting, we should not wait forever.We should cleanup gc sessions here as soon
789
+ // as possible to call FinishSession() and cleanup resources.
790
+ if (std::cv_status::timeout == session_waker_.wait_for (lock, options_.timeout ))
791
+ {
792
+ cleanupGCSessions ();
793
+ }
786
794
}
787
795
return true ;
788
796
}
Original file line number Diff line number Diff line change @@ -77,9 +77,12 @@ void Session::SendRequest(
77
77
// reuse it instead of creating a new one.
78
78
http_client_.MaybeSpawnBackgroundThread ();
79
79
}
80
- else if (callback)
80
+ else
81
81
{
82
- callback->OnEvent (opentelemetry::ext::http::client::SessionState::CreateFailed, " " );
82
+ if (callback)
83
+ {
84
+ callback->OnEvent (opentelemetry::ext::http::client::SessionState::CreateFailed, " " );
85
+ }
83
86
is_session_active_.store (false , std::memory_order_release);
84
87
}
85
88
}
@@ -176,8 +179,9 @@ bool HttpClient::CancelAllSessions() noexcept
176
179
{
177
180
std::unordered_map<uint64_t , std::shared_ptr<Session>> sessions;
178
181
{
182
+ // We can only cleanup session and curl handles in the IO thread.
179
183
std::lock_guard<std::mutex> lock_guard{sessions_m_};
180
- sessions. swap ( sessions_) ;
184
+ sessions = sessions_;
181
185
}
182
186
183
187
if (sessions.empty ())
@@ -200,8 +204,9 @@ bool HttpClient::FinishAllSessions() noexcept
200
204
{
201
205
std::unordered_map<uint64_t , std::shared_ptr<Session>> sessions;
202
206
{
207
+ // We can only cleanup session and curl handles in the IO thread.
203
208
std::lock_guard<std::mutex> lock_guard{sessions_m_};
204
- sessions. swap ( sessions_) ;
209
+ sessions = sessions_;
205
210
}
206
211
207
212
if (sessions.empty ())
Original file line number Diff line number Diff line change 1
1
// Copyright The OpenTelemetry Authors
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
+ #include < cstring>
5
+
4
6
#include " opentelemetry/ext/http/client/curl/http_operation_curl.h"
5
7
6
8
#include " opentelemetry/ext/http/client/curl/http_client_curl.h"
You can’t perform that action at this time.
0 commit comments