From 28e25765893e6783a80d625d93280fc590a0f665 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Fri, 5 Jan 2024 19:48:21 +0100 Subject: [PATCH] Fix: race-condition when quitting the game with libcurl (#11688) There could be a callback in _new_http_callbacks that is not processed yet. All callbacks in _http_callbacks were cancelled, but not the ones in _new_http_callbacks --- src/network/core/http_curl.cpp | 7 +++---- src/network/core/http_shared.h | 14 -------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/network/core/http_curl.cpp b/src/network/core/http_curl.cpp index c7a454da8b..e238a81772 100644 --- a/src/network/core/http_curl.cpp +++ b/src/network/core/http_curl.cpp @@ -278,10 +278,9 @@ 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(); - } + /* Ensure the callbacks are handled. This is mostly needed as we send + * a survey just before close, and that might be pending here. */ + NetworkHTTPSocketHandler::HTTPReceive(); { std::lock_guard lock(_http_mutex); diff --git a/src/network/core/http_shared.h b/src/network/core/http_shared.h index b7549e8fe7..ec3ae79348 100644 --- a/src/network/core/http_shared.h +++ b/src/network/core/http_shared.h @@ -97,20 +97,6 @@ public: return this->queue.empty(); } - - /** - * Clear everything in the queue. - * - * Should be called from the Game Thread. - */ - void ClearQueue() - { - std::lock_guard lock(this->mutex); - - this->queue.clear(); - this->queue_cv.notify_all(); - } - HTTPThreadSafeCallback(HTTPCallback *callback) : callback(callback) {} ~HTTPThreadSafeCallback()