diff --git a/src/httpfetch.cpp b/src/httpfetch.cpp index 3fac21f928..18a2a8ee20 100644 --- a/src/httpfetch.cpp +++ b/src/httpfetch.cpp @@ -402,6 +402,8 @@ const HTTPFetchResult * HTTPFetchOngoing::complete(CURLcode res) HTTPFetchOngoing::~HTTPFetchOngoing() { if (multi) { + // Note: this can block if curl is stuck waiting for DNS, see + // CURLMcode mres = curl_multi_remove_handle(multi, curl); if (mres != CURLM_OK) { errorstream << "curl_multi_remove_handle" @@ -635,6 +637,8 @@ protected: while (!stopRequested()) { BEGIN_DEBUG_EXCEPTION_HANDLER + const u64 t0 = porting::getTimeMs(); + /* 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 (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) { - if (g_httpfetch_thread->isRunning()) { - Event event; - g_httpfetch_thread->requestClear(caller, &event); - event.wait(); - } else { - g_httpfetch_thread->requestClear(caller, nullptr); - } + g_httpfetch_thread->requestClear(caller, nullptr); } bool httpfetch_sync_interruptible(const HTTPFetchRequest &fetch_request,