From 91f02768f9ab122b31498e3829e20437c3b309f7 Mon Sep 17 00:00:00 2001 From: Gilbert Chen Date: Sat, 13 Jan 2018 00:23:33 -0500 Subject: [PATCH] Retry on download errors for Hubic which may return 404 for existing chunks --- src/duplicacy_chunkdownloader.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/duplicacy_chunkdownloader.go b/src/duplicacy_chunkdownloader.go index 71a1c03..1647157 100644 --- a/src/duplicacy_chunkdownloader.go +++ b/src/duplicacy_chunkdownloader.go @@ -317,6 +317,12 @@ func (downloader *ChunkDownloader) Download(threadIndex int, task ChunkDownloadT } if !exist { + // Retry for the Hubic backend as it may return 404 even when the chunk exists + if _, ok := downloader.storage.(*HubicStorage); ok && downloadAttempt < MaxDownloadAttempts { + LOG_WARN("DOWNLOAD_RETRY", "Failed to find the chunk %s; retrying", chunkID) + continue + } + // A chunk is not found. This is a serious error and hopefully it will never happen. if err != nil { LOG_FATAL("DOWNLOAD_CHUNK", "Chunk %s can't be found: %v", chunkID, err) @@ -340,7 +346,9 @@ func (downloader *ChunkDownloader) Download(threadIndex int, task ChunkDownloadT err = downloader.storage.DownloadFile(threadIndex, chunkPath, chunk) if err != nil { - if err == io.ErrUnexpectedEOF && downloadAttempt < MaxDownloadAttempts { + _, isHubic := downloader.storage.(*HubicStorage) + // Retry on EOF or if it is a Hubic backend as it may return 404 even when the chunk exists + if (err == io.ErrUnexpectedEOF || isHubic) && downloadAttempt < MaxDownloadAttempts { LOG_WARN("DOWNLOAD_RETRY", "Failed to download the chunk %s: %v; retrying", chunkID, err) chunk.Reset(false) continue