From c729ccad325cd8c6a805655bdd4a49a56f00d5e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 15 Feb 2024 23:52:57 +0100 Subject: [PATCH] Abort new HTTP requests immediately when shutting down `CHttp` Immediately cancel new HTTP requests instead of enqueuing them when already shutting down `CHttp`. Otherwise, `CChooseMaster` may wait forever for HTTP requests to be completed while the client is shutting down, if `CHttp` was shutdown while `CChooseMaster` is not waiting for an existing HTTP request. Not directly caused by #7962, but it made it more likely to happen. Closes #7980. --- src/engine/shared/http.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/engine/shared/http.cpp b/src/engine/shared/http.cpp index e47962773..ebe46c836 100644 --- a/src/engine/shared/http.cpp +++ b/src/engine/shared/http.cpp @@ -560,9 +560,16 @@ void CHttp::RunLoop() void CHttp::Run(std::shared_ptr pRequest) { + std::shared_ptr pRequestImpl = std::static_pointer_cast(pRequest); std::unique_lock Lock(m_Lock); + if(m_Shutdown) + { + str_copy(pRequestImpl->m_aErr, "Shutting down"); + pRequestImpl->OnCompletionInternal(CURLE_ABORTED_BY_CALLBACK); + return; + } m_Cv.wait(Lock, [this]() { return m_State != CHttp::UNINITIALIZED; }); - m_PendingRequests.emplace_back(std::static_pointer_cast(pRequest)); + m_PendingRequests.emplace_back(pRequestImpl); curl_multi_wakeup(m_pMultiH); }