From 6bb00c50d81cfdf21ac9ab1c4b0a021081845064 Mon Sep 17 00:00:00 2001 From: azyges <229218900+azyges@users.noreply.github.com> Date: Wed, 22 Oct 2025 03:33:51 +0900 Subject: [PATCH] improve logging fallback --- .../WebAPI/Files/FileDownloadManager.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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();