Skip to content

Commit 8496a7d

Browse files
committed
fix(downloads): widen retry exception guard to include SSL/AuthenticationException
1 parent 387c7b9 commit 8496a7d

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

StabilityMatrix.Core/Models/TrackedDownload.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Diagnostics.CodeAnalysis;
2+
using System.Security.Authentication;
23
using System.Text.Json.Serialization;
34
using AsyncAwaitBestPractices;
45
using NLog;
@@ -316,6 +317,15 @@ private void DoCleanup()
316317
}
317318
}
318319

320+
/// <summary>
321+
/// Returns true for transient network/SSL exceptions that are safe to retry.
322+
/// </summary>
323+
private static bool IsTransientNetworkException(Exception? ex) =>
324+
ex is IOException or AuthenticationException
325+
|| ex?.InnerException is IOException or AuthenticationException
326+
|| ex is AggregateException ae
327+
&& ae.InnerExceptions.Any(e => e is IOException or AuthenticationException);
328+
319329
/// <summary>
320330
/// Invoked by the task's completion callback
321331
/// </summary>
@@ -349,7 +359,7 @@ private void OnDownloadTaskCompleted(Task task)
349359
// Set the exception
350360
Exception = task.Exception;
351361

352-
if ((Exception is IOException || Exception?.InnerException is IOException) && attempts < 3)
362+
if (IsTransientNetworkException(Exception) && attempts < 3)
353363
{
354364
attempts++;
355365
Logger.Warn(

0 commit comments

Comments
 (0)