about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-09-01T14·51+0200
committerEelco Dolstra <edolstra@gmail.com>2017-09-01T14·51+0200
commit8215b75d36a6c60649dfc8721b8ddd44fbcf697c (patch)
tree6d26ab94385850912063a894d06eda0f87d797b0 /src/libstore
parent7a108d904e9d3bb9ef94487c37b35a050c315a52 (diff)
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.)
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/download.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libstore/download.cc b/src/libstore/download.cc
index 054244c7b8b7..f5304daeefd2 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<std::chrono::milliseconds>(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)