diff --git a/LightlessSync/WebAPI/Files/FileDownloadManager.cs b/LightlessSync/WebAPI/Files/FileDownloadManager.cs index cc82d04..b8f81f2 100644 --- a/LightlessSync/WebAPI/Files/FileDownloadManager.cs +++ b/LightlessSync/WebAPI/Files/FileDownloadManager.cs @@ -215,6 +215,26 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase await Task.Delay(retryDelay, ct).ConfigureAwait(false); } + catch (TaskCanceledException ex) when (!ct.IsCancellationRequested) + { + response?.Dispose(); + retryCount++; + + Logger.LogWarning(ex, "Cancellation/timeout during download of {requestUrl}. Attempt {attempt} of {maxRetries}", requestUrl, retryCount, maxRetries); + + if (retryCount >= maxRetries) + { + Logger.LogError("Max retries reached for {requestUrl} after TaskCanceledException", requestUrl); + throw; + } + + await Task.Delay(retryDelay, ct).ConfigureAwait(false); + } + catch (OperationCanceledException) when (ct.IsCancellationRequested) + { + response?.Dispose(); + throw; + } catch (HttpRequestException ex) { response?.Dispose();