From 4b5b6b73765ba252d90123e47cf9f8b45ff818b4 Mon Sep 17 00:00:00 2001 From: BEagle1984 Date: Thu, 16 Mar 2023 14:44:42 +0100 Subject: [PATCH] fix: correctly stack MaxFailedAttempts in ErrorPolicyChain --- Directory.Build.props | 2 +- docs/releases.md | 7 ++++++- .../Inbound/ErrorHandling/ErrorPolicyChain.cs | 12 +++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 44bb5d360..889b8a91a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 4.1.1$(BaseVersionSuffix) + 4.1.2$(BaseVersionSuffix) 1 $(BaseVersionSuffix) diff --git a/docs/releases.md b/docs/releases.md index 0a2100086..576c9a1e7 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -4,13 +4,18 @@ uid: releases # Releases +## [4.1.2](https://github.com/BEagle1984/silverback/releases/tag/v4.1.2) + +### Fixes + +* Fix chained error policies attempts counter + ## [4.1.1](https://github.com/BEagle1984/silverback/releases/tag/v4.1.1) ### Fixes * Fix bug in outbox producer writing to the wrong endpoint [[#165](https://github.com/BEagle1984/silverback/issues/165)] - ## [4.1.0](https://github.com/BEagle1984/silverback/releases/tag/v4.1.0) ### What's new diff --git a/src/Silverback.Integration/Messaging/Inbound/ErrorHandling/ErrorPolicyChain.cs b/src/Silverback.Integration/Messaging/Inbound/ErrorHandling/ErrorPolicyChain.cs index 91d569501..f90e39772 100644 --- a/src/Silverback.Integration/Messaging/Inbound/ErrorHandling/ErrorPolicyChain.cs +++ b/src/Silverback.Integration/Messaging/Inbound/ErrorHandling/ErrorPolicyChain.cs @@ -17,6 +17,8 @@ namespace Silverback.Messaging.Inbound.ErrorHandling /// public class ErrorPolicyChain : IErrorPolicy { + private bool _failedAttemptsStacked; + /// /// Initializes a new instance of the class. /// @@ -50,19 +52,23 @@ public IErrorPolicyImplementation Build(IServiceProvider serviceProvider) => .Cast(), serviceProvider.GetRequiredService>()); - private static IReadOnlyCollection StackMaxFailedAttempts( - IReadOnlyCollection policies) + private IReadOnlyCollection StackMaxFailedAttempts(IReadOnlyCollection policies) { + if (_failedAttemptsStacked) + return policies; + var totalAttempts = 0; foreach (var policy in policies) { - if (policy.MaxFailedAttemptsCount == null || policy.MaxFailedAttemptsCount <= 0) + if (policy.MaxFailedAttemptsCount is null or <= 0) continue; totalAttempts += policy.MaxFailedAttemptsCount.Value; policy.MaxFailedAttemptsCount = totalAttempts; } + _failedAttemptsStacked = true; + return policies; }