Skip to content

Commit 8215b75

Browse files
committed
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.)
1 parent 7a108d9 commit 8215b75

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/libstore/download.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ struct CurlDownloader : public Downloader
183183
return 0;
184184
}
185185

186+
long lowSpeedTimeout = 300;
187+
186188
void init()
187189
{
188190
if (!req) req = curl_easy_init();
@@ -231,6 +233,9 @@ struct CurlDownloader : public Downloader
231233

232234
curl_easy_setopt(req, CURLOPT_CONNECTTIMEOUT, settings.connectTimeout.get());
233235

236+
curl_easy_setopt(req, CURLOPT_LOW_SPEED_LIMIT, 1L);
237+
curl_easy_setopt(req, CURLOPT_LOW_SPEED_TIME, lowSpeedTimeout);
238+
234239
/* If no file exist in the specified path, curl continues to work
235240
anyway as if netrc support was disabled. */
236241
curl_easy_setopt(req, CURLOPT_NETRC_FILE, settings.netrcFile.get().c_str());
@@ -422,7 +427,7 @@ struct CurlDownloader : public Downloader
422427
auto sleepTimeMs =
423428
nextWakeup != std::chrono::steady_clock::time_point()
424429
? std::max(0, (int) std::chrono::duration_cast<std::chrono::milliseconds>(nextWakeup - std::chrono::steady_clock::now()).count())
425-
: 1000000000;
430+
: 10000;
426431
vomit("download thread waiting for %d ms", sleepTimeMs);
427432
mc = curl_multi_wait(curlm, extraFDs, 1, sleepTimeMs, &numfds);
428433
if (mc != CURLM_OK)

0 commit comments

Comments
 (0)