From 8215b75d36a6c60649dfc8721b8ddd44fbcf697c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 1 Sep 2017 16:51:26 +0200 Subject: [PATCH] Abort curl downloads if there is no progress for 5 minutes Maybe this will fix the curl hangs on macOS. (We could also use CURLOPT_TIMEOUT but that seems more of a sledgehammer.) --- src/libstore/download.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libstore/download.cc b/src/libstore/download.cc index 054244c7b..f5304daee 100644 --- a/src/libstore/download.cc +++ b/src/libstore/download.cc @@ -183,6 +183,8 @@ struct CurlDownloader : public Downloader return 0; } + long lowSpeedTimeout = 300; + void init() { if (!req) req = curl_easy_init(); @@ -231,6 +233,9 @@ struct CurlDownloader : public Downloader curl_easy_setopt(req, CURLOPT_CONNECTTIMEOUT, settings.connectTimeout.get()); + curl_easy_setopt(req, CURLOPT_LOW_SPEED_LIMIT, 1L); + curl_easy_setopt(req, CURLOPT_LOW_SPEED_TIME, lowSpeedTimeout); + /* If no file exist in the specified path, curl continues to work anyway as if netrc support was disabled. */ curl_easy_setopt(req, CURLOPT_NETRC_FILE, settings.netrcFile.get().c_str()); @@ -422,7 +427,7 @@ struct CurlDownloader : public Downloader auto sleepTimeMs = nextWakeup != std::chrono::steady_clock::time_point() ? std::max(0, (int) std::chrono::duration_cast(nextWakeup - std::chrono::steady_clock::now()).count()) - : 1000000000; + : 10000; vomit("download thread waiting for %d ms", sleepTimeMs); mc = curl_multi_wait(curlm, extraFDs, 1, sleepTimeMs, &numfds); if (mc != CURLM_OK)