diff --git a/ext/src/http/client/curl/http_client_curl.cc b/ext/src/http/client/curl/http_client_curl.cc index 94bbf9fa7b..287059a1c6 100644 --- a/ext/src/http/client/curl/http_client_curl.cc +++ b/ext/src/http/client/curl/http_client_curl.cc @@ -244,6 +244,7 @@ void HttpClient::CleanupSession(uint64_t session_id) } } + bool need_wakeup_background_thread = false; { std::lock_guard lock_guard{session_ids_m_}; pending_to_add_session_ids_.erase(session_id); @@ -259,10 +260,15 @@ void HttpClient::CleanupSession(uint64_t session_id) { // If this session is already running, give it to the background thread for cleanup. pending_to_abort_sessions_[session_id] = std::move(session); - wakeupBackgroundThread(); + need_wakeup_background_thread = true; } } } + + if (need_wakeup_background_thread) + { + wakeupBackgroundThread(); + } } void HttpClient::MaybeSpawnBackgroundThread() @@ -519,7 +525,8 @@ bool HttpClient::doRemoveSessions() std::lock_guard session_id_lock_guard{session_ids_m_}; pending_to_remove_session_handles_.swap(pending_to_remove_session_handles); pending_to_remove_sessions_.swap(pending_to_remove_sessions); - + } + { // If user callback do not call CancelSession or FinishSession, We still need to remove it // from sessions_ std::lock_guard session_lock_guard{sessions_m_};