From c4040a707823999d4612922a77ca6485dc1ca06f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 10 Mar 2026 21:31:03 -0500 Subject: cap number of tracked exceptions --- src/slskd/Common/Retry.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/slskd/Common/Retry.cs b/src/slskd/Common/Retry.cs index 457d32fb..80d0bc7f 100644 --- a/src/slskd/Common/Retry.cs +++ b/src/slskd/Common/Retry.cs @@ -37,6 +37,7 @@ namespace slskd /// The maximum number of retry attempts. /// The base delay in milliseconds. /// The maximum delay in milliseconds. + /// The maximum number of Exceptions to keep in history. /// The token to monitor for cancellation requests. /// The execution context. public static async Task Do( @@ -47,13 +48,14 @@ namespace slskd int maxAttempts = 3, int baseDelayInMilliseconds = 1000, int maxDelayInMilliseconds = int.MaxValue, + int exceptionHistoryLimit = 5, CancellationToken cancellationToken = default) { await Do(async () => { await task(); return Task.FromResult(null); - }, isRetryable, onRetry, onFailure, maxAttempts, baseDelayInMilliseconds, maxDelayInMilliseconds, cancellationToken); + }, isRetryable, onRetry, onFailure, maxAttempts, baseDelayInMilliseconds, maxDelayInMilliseconds, exceptionHistoryLimit, cancellationToken); } /// @@ -66,6 +68,7 @@ namespace slskd /// The maximum number of retry attempts. /// The base delay in milliseconds. /// The maximum delay in milliseconds. + /// The maximum number of Exceptions to keep in history. /// The token to monitor for cancellation requests. /// The Type of the logic return value. /// The execution context. @@ -77,11 +80,12 @@ namespace slskd int maxAttempts = 3, int baseDelayInMilliseconds = 1000, int maxDelayInMilliseconds = int.MaxValue, + int exceptionHistoryLimit = 5, CancellationToken cancellationToken = default) { isRetryable ??= (_, _) => true; - var exceptions = new List(); + var exceptions = new Queue(); for (int attempts = 0; attempts < maxAttempts; attempts++) { @@ -104,7 +108,12 @@ namespace slskd } catch (Exception ex) { - exceptions.Add(ex); + exceptions.Enqueue(ex); + + if (exceptions.Count > exceptionHistoryLimit) + { + exceptions.Dequeue(); + } try { -- cgit v1.2.3