mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-12 16:15:20 +02:00
Do not block in httpfetch_request_clear() (#16303)
This commit is contained in:
@@ -402,6 +402,8 @@ const HTTPFetchResult * HTTPFetchOngoing::complete(CURLcode res)
|
|||||||
HTTPFetchOngoing::~HTTPFetchOngoing()
|
HTTPFetchOngoing::~HTTPFetchOngoing()
|
||||||
{
|
{
|
||||||
if (multi) {
|
if (multi) {
|
||||||
|
// Note: this can block if curl is stuck waiting for DNS, see
|
||||||
|
// <https://github.com/luanti-org/luanti/issues/16272>
|
||||||
CURLMcode mres = curl_multi_remove_handle(multi, curl);
|
CURLMcode mres = curl_multi_remove_handle(multi, curl);
|
||||||
if (mres != CURLM_OK) {
|
if (mres != CURLM_OK) {
|
||||||
errorstream << "curl_multi_remove_handle"
|
errorstream << "curl_multi_remove_handle"
|
||||||
@@ -635,6 +637,8 @@ protected:
|
|||||||
while (!stopRequested()) {
|
while (!stopRequested()) {
|
||||||
BEGIN_DEBUG_EXCEPTION_HANDLER
|
BEGIN_DEBUG_EXCEPTION_HANDLER
|
||||||
|
|
||||||
|
const u64 t0 = porting::getTimeMs();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Handle new async requests
|
Handle new async requests
|
||||||
*/
|
*/
|
||||||
@@ -667,6 +671,16 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
If we took suspiciously long, warn.
|
||||||
|
*/
|
||||||
|
const u64 tdelta = porting::getTimeMs() - t0;
|
||||||
|
if (tdelta > 300) {
|
||||||
|
warningstream << "CurlFetchThread blocked for " << tdelta << "ms"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
If there are ongoing requests, wait for data
|
If there are ongoing requests, wait for data
|
||||||
(with a timeout of 100ms so that new requests
|
(with a timeout of 100ms so that new requests
|
||||||
@@ -738,13 +752,7 @@ void httpfetch_async(const HTTPFetchRequest &fetch_request)
|
|||||||
|
|
||||||
static void httpfetch_request_clear(u64 caller)
|
static void httpfetch_request_clear(u64 caller)
|
||||||
{
|
{
|
||||||
if (g_httpfetch_thread->isRunning()) {
|
g_httpfetch_thread->requestClear(caller, nullptr);
|
||||||
Event event;
|
|
||||||
g_httpfetch_thread->requestClear(caller, &event);
|
|
||||||
event.wait();
|
|
||||||
} else {
|
|
||||||
g_httpfetch_thread->requestClear(caller, nullptr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool httpfetch_sync_interruptible(const HTTPFetchRequest &fetch_request,
|
bool httpfetch_sync_interruptible(const HTTPFetchRequest &fetch_request,
|
||||||
|
Reference in New Issue
Block a user