Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK] Fix deadlock when shuting down http client #2337

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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