Fix: libcurl HTTP thread race at uninit preventing thread exit

This commit is contained in:
Jonathan G Rennison
2024-01-04 01:02:22 +00:00
committed by Patric Stout
parent c6dafb0865
commit 51ef416b49
2 changed files with 28 additions and 5 deletions

View File

@@ -230,8 +230,10 @@ void HttpThread()
request->callback.OnFailure();
}
/* Wait till the callback tells us all data is dequeued. */
request->callback.WaitTillEmpty();
/* Wait till the callback tells us all data is dequeued, or _http_thread_exit has been set. */
request->callback.WaitTillEmptyOrCondition([]() -> bool {
return _http_thread_exit;
});
}
curl_easy_cleanup(curl);
@@ -278,6 +280,11 @@ void NetworkHTTPUninitialize()
_http_thread_exit = true;
/* Queues must be cleared (and the queue CV signalled) after _http_thread_exit is set to ensure that the HTTP thread can exit */
for (auto &callback : _http_callbacks) {
callback->ClearQueue();
}
{
std::lock_guard<std::mutex> lock(_http_mutex);
_http_cv.notify_one();