Skip to content

Commit

Permalink
Backport fix to remove report of circuit breaker disarmed every 30 sec (
Browse files Browse the repository at this point in the history
  • Loading branch information
TravisNickels authored Jul 26, 2024
1 parent a1b072e commit b14216e
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/NServiceBus.Transport.Msmq/FailureRateCircuitBreaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,28 @@ 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(() =>
{
Logger.WarnFormat("The circuit breaker for {0} will now be triggered", name);
triggerAction(lastException);
});
}
else if (result == 1)
else if (failures == 1)
{
Logger.WarnFormat("The circuit breaker for {0} is now in the armed state", name);
}
Expand Down

0 comments on commit b14216e

Please sign in to comment.