Skip to content

Commit

Permalink
Fix deadlock when shuting down http client. (open-telemetry#2337)
Browse files Browse the repository at this point in the history
  • Loading branch information
owent authored Sep 28, 2023
1 parent a45081a commit 368ee79
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ext/src/http/client/curl/http_client_curl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ void HttpClient::CleanupSession(uint64_t session_id)
}
}

bool need_wakeup_background_thread = false;
{
std::lock_guard<std::recursive_mutex> lock_guard{session_ids_m_};
pending_to_add_session_ids_.erase(session_id);
Expand All @@ -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()
Expand Down Expand Up @@ -519,7 +525,8 @@ bool HttpClient::doRemoveSessions()
std::lock_guard<std::recursive_mutex> 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<std::mutex> session_lock_guard{sessions_m_};
Expand Down

0 comments on commit 368ee79

Please sign in to comment.