@@ -302,7 +302,7 @@ HttpClient::~HttpClient()
302302 }
303303
304304 // Force to abort all sessions
305- CancelAllSessions ();
305+ InternalCancelAllSessions ();
306306
307307 if (!background_thread)
308308 {
@@ -342,27 +342,7 @@ std::shared_ptr<opentelemetry::ext::http::client::Session> HttpClient::CreateSes
342342
343343bool HttpClient::CancelAllSessions () noexcept
344344{
345- // CancelSession may change sessions_, we can not change a container while iterating it.
346- while (true )
347- {
348- std::unordered_map<uint64_t , std::shared_ptr<Session>> sessions;
349- {
350- // We can only cleanup session and curl handles in the IO thread.
351- std::lock_guard<std::mutex> lock_guard{sessions_m_};
352- sessions = sessions_;
353- }
354-
355- if (sessions.empty ())
356- {
357- break ;
358- }
359-
360- for (auto &session : sessions)
361- {
362- session.second ->CancelSession ();
363- }
364- }
365- return true ;
345+ return InternalCancelAllSessions ();
366346}
367347
368348bool HttpClient::FinishAllSessions () noexcept
@@ -435,6 +415,31 @@ void HttpClient::CleanupSession(uint64_t session_id)
435415 }
436416}
437417
418+ bool HttpClient::InternalCancelAllSessions () noexcept
419+ {
420+ // CancelSession may change sessions_, we can not change a container while iterating it.
421+ while (true )
422+ {
423+ std::unordered_map<uint64_t , std::shared_ptr<Session>> sessions;
424+ {
425+ // We can only cleanup session and curl handles in the IO thread.
426+ std::lock_guard<std::mutex> lock_guard{sessions_m_};
427+ sessions = sessions_;
428+ }
429+
430+ if (sessions.empty ())
431+ {
432+ break ;
433+ }
434+
435+ for (auto &session : sessions)
436+ {
437+ session.second ->CancelSession ();
438+ }
439+ }
440+ return true ;
441+ }
442+
438443bool HttpClient::MaybeSpawnBackgroundThread ()
439444{
440445 std::lock_guard<std::mutex> lock_guard{background_thread_m_};
0 commit comments