From b14216e63bdb7392bcaff7d932f3f28d5d1550bd Mon Sep 17 00:00:00 2001 From: Travis Nickels Date: Fri, 26 Jul 2024 10:12:49 -0700 Subject: [PATCH] Backport fix to remove report of circuit breaker disarmed every 30 sec (#723) --- .../FailureRateCircuitBreaker.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/NServiceBus.Transport.Msmq/FailureRateCircuitBreaker.cs b/src/NServiceBus.Transport.Msmq/FailureRateCircuitBreaker.cs index c13bd19e..9596a7db 100644 --- a/src/NServiceBus.Transport.Msmq/FailureRateCircuitBreaker.cs +++ b/src/NServiceBus.Transport.Msmq/FailureRateCircuitBreaker.cs @@ -15,21 +15,20 @@ public FailureRateCircuitBreaker(string name, int maximumFailuresPerSecond, Acti timer = new Timer(_ => FlushHistory(), null, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(30)); } - public void Dispose() - { - timer?.Dispose(); - } + public void Dispose() => timer.Dispose(); void FlushHistory() { - Interlocked.Exchange(ref failureCount, 0); - Logger.InfoFormat("The circuit breaker for {0} is now disarmed", name); + if (Interlocked.Exchange(ref failureCount, 0) > 0) + { + Logger.InfoFormat("The circuit breaker for {0} is now disarmed", name); + } } public void Failure(Exception lastException) { - var result = Interlocked.Increment(ref failureCount); - if (result > maximumFailuresPerThirtySeconds) + var failures = Interlocked.Increment(ref failureCount); + if (failures > maximumFailuresPerThirtySeconds) { _ = Task.Run(() => { @@ -37,7 +36,7 @@ public void Failure(Exception lastException) triggerAction(lastException); }); } - else if (result == 1) + else if (failures == 1) { Logger.WarnFormat("The circuit breaker for {0} is now in the armed state", name); }