From 075f494ec6fe555b53af6f7ca4b7555ddf074ec0 Mon Sep 17 00:00:00 2001 From: Roger Far Date: Thu, 28 Oct 2021 17:15:47 -0600 Subject: [PATCH] Fixed simple downloader retrying. --- server/RdtClient.Service/Services/DownloadClient.cs | 9 +++++++-- .../Services/Downloaders/SimpleDownloader.cs | 9 +++++++-- server/RdtClient.Service/Services/TorrentRunner.cs | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/server/RdtClient.Service/Services/DownloadClient.cs b/server/RdtClient.Service/Services/DownloadClient.cs index 622bed8..c28acb6 100644 --- a/server/RdtClient.Service/Services/DownloadClient.cs +++ b/server/RdtClient.Service/Services/DownloadClient.cs @@ -63,7 +63,7 @@ namespace RdtClient.Service.Services Downloader.DownloadComplete += (_, args) => { Finished = true; - Error = args.Error; + Error ??= args.Error; }; Downloader.DownloadProgress += (_, args) => @@ -74,13 +74,18 @@ namespace RdtClient.Service.Services }; var result = await Downloader.Download(); - + await Task.Delay(1000); return result; } catch (Exception ex) { + if (Downloader != null) + { + await Downloader.Cancel(); + } + Error = $"An unexpected error occurred preparing download {_download.Link} for torrent {_torrent.RdName}: {ex.Message}"; Finished = true; diff --git a/server/RdtClient.Service/Services/Downloaders/SimpleDownloader.cs b/server/RdtClient.Service/Services/Downloaders/SimpleDownloader.cs index ed3c908..c2e56b0 100644 --- a/server/RdtClient.Service/Services/Downloaders/SimpleDownloader.cs +++ b/server/RdtClient.Service/Services/Downloaders/SimpleDownloader.cs @@ -41,8 +41,8 @@ namespace RdtClient.Service.Services.Downloaders { await StartDownloadTask(); }); - - return null; + + return Task.FromResult(null); } public Task Cancel() @@ -137,6 +137,11 @@ namespace RdtClient.Service.Services.Downloaders } } + if (_cancelled) + { + throw new Exception("Download cancelled"); + } + if (timeout <= DateTimeOffset.UtcNow) { throw new Exception($"Download timed out"); diff --git a/server/RdtClient.Service/Services/TorrentRunner.cs b/server/RdtClient.Service/Services/TorrentRunner.cs index 58af329..0e0984c 100644 --- a/server/RdtClient.Service/Services/TorrentRunner.cs +++ b/server/RdtClient.Service/Services/TorrentRunner.cs @@ -184,8 +184,8 @@ namespace RdtClient.Service.Services { Log($"Retrying download", download, download.Torrent); - await _downloads.UpdateRetryCount(downloadId, download.RetryCount + 1); await _downloads.Reset(downloadId); + await _downloads.UpdateRetryCount(downloadId, download.RetryCount + 1); } else if (download.Torrent.RetryCount < TorrentRetryCount) {