diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-03-10 21:31:03 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-03-10 21:31:03 -0500 |
| commit | c4040a707823999d4612922a77ca6485dc1ca06f (patch) | |
| tree | dbdb73eb90f82b1434b7edab00cf5ff0fb8fa1f8 | |
| parent | a7b5682ccaf37cbfad5b5302cfbeab5fd3d577b6 (diff) | |
| download | slskd-c4040a707823999d4612922a77ca6485dc1ca06f.tar.gz | |
cap number of tracked exceptions
| -rw-r--r-- | src/slskd/Common/Retry.cs | 15 |
1 files changed, 12 insertions, 3 deletions
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 /// <param name="maxAttempts">The maximum number of retry attempts.</param> /// <param name="baseDelayInMilliseconds">The base delay in milliseconds.</param> /// <param name="maxDelayInMilliseconds">The maximum delay in milliseconds.</param> + /// <param name="exceptionHistoryLimit">The maximum number of Exceptions to keep in history.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <returns>The execution context.</returns> 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<object>(async () => { await task(); return Task.FromResult<object>(null); - }, isRetryable, onRetry, onFailure, maxAttempts, baseDelayInMilliseconds, maxDelayInMilliseconds, cancellationToken); + }, isRetryable, onRetry, onFailure, maxAttempts, baseDelayInMilliseconds, maxDelayInMilliseconds, exceptionHistoryLimit, cancellationToken); } /// <summary> @@ -66,6 +68,7 @@ namespace slskd /// <param name="maxAttempts">The maximum number of retry attempts.</param> /// <param name="baseDelayInMilliseconds">The base delay in milliseconds.</param> /// <param name="maxDelayInMilliseconds">The maximum delay in milliseconds.</param> + /// <param name="exceptionHistoryLimit">The maximum number of Exceptions to keep in history.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <typeparam name="T">The Type of the logic return value.</typeparam> /// <returns>The execution context.</returns> @@ -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<Exception>(); + var exceptions = new Queue<Exception>(); 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 { |
