Skip to content

Commit

Permalink
downloader: when retry but can't resume, retry the whole file
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Mar 30, 2020
1 parent e322a16 commit f8a1cc2
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/libstore/download.cc
Expand Up @@ -308,7 +308,7 @@ struct CurlDownloader : public Downloader
curl_easy_setopt(req, CURLOPT_NETRC_FILE, settings.netrcFile.get().c_str());
curl_easy_setopt(req, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);

if (writtenToSink)
if (writtenToSink && acceptRanges && encoding.empty())
curl_easy_setopt(req, CURLOPT_RESUME_FROM_LARGE, writtenToSink);

result.data = std::make_shared<std::string>();
Expand Down Expand Up @@ -416,14 +416,10 @@ struct CurlDownloader : public Downloader
download after a while. If we're writing to a
sink, we can only retry if the server supports
ranged requests. */
if (err == Transient
&& attempt < request.tries
&& (!this->request.dataCallback
|| writtenToSink == 0
|| (acceptRanges && encoding.empty())))
if (err == Transient && attempt < request.tries)
{
int ms = request.baseRetryTimeMs * std::pow(2.0f, attempt - 1 + std::uniform_real_distribution<>(0.0, 0.5)(downloader.mt19937));
if (writtenToSink)
if (writtenToSink && acceptRanges && encoding.empty())
warn("%s; retrying from offset %d in %d ms", exc.what(), writtenToSink, ms);
else
warn("%s; retrying in %d ms", exc.what(), ms);
Expand Down

0 comments on commit f8a1cc2

Please sign in to comment.