Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop flooding logs in FailureRateCircuitBreaker (#630) #633

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace NServiceBus.Transport.Msmq.DelayedDelivery
using Logging;
using Routing;

class DelayedDeliveryPump
class DelayedDeliveryPump : IDisposable
{
public DelayedDeliveryPump(MsmqMessageDispatcher dispatcher,
DueDelayedMessagePoller poller,
Expand Down Expand Up @@ -137,6 +137,12 @@ async Task<ErrorHandleResult> OnError(ErrorContext errorContext, CancellationTok
return ErrorHandleResult.Handled;
}

public void Dispose()
{
poller.Dispose();
storeCircuitBreaker.Dispose();
}

readonly MsmqMessageDispatcher dispatcher;
readonly DueDelayedMessagePoller poller;
readonly IDelayedMessageStore storage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace NServiceBus.Transport.Msmq.DelayedDelivery
using Routing;
using Unicast.Queuing;

class DueDelayedMessagePoller
class DueDelayedMessagePoller : IDisposable
{
public DueDelayedMessagePoller(MsmqMessageDispatcher dispatcher,
IDelayedMessageStore delayedMessageStore,
Expand Down Expand Up @@ -334,6 +334,14 @@ await dispatcher.Dispatch(new TransportOperations(transportOperation), transport
}
}

public void Dispose()
{
fetchCircuitBreaker.Dispose();
dispatchCircuitBreaker.Dispose();
failureHandlingCircuitBreaker.Dispose();
tokenSource?.Dispose();
}

static readonly ILog Log = LogManager.GetLogger<DueDelayedMessagePoller>();
static readonly TimeSpan MaxSleepDuration = TimeSpan.FromMinutes(1);

Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public override async Task Shutdown(CancellationToken cancellationToken = defaul
if (delayedDeliveryPump != null)
{
await delayedDeliveryPump.Stop(cancellationToken).ConfigureAwait(false);
delayedDeliveryPump.Dispose();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ public Task Failure(Exception exception, CancellationToken cancellationToken = d
return Task.Delay(TimeSpan.FromSeconds(1), CancellationToken.None);
}

public void Dispose()
{
//Injected
}
public void Dispose() => timer.Dispose();

void CircuitBreakerTriggered(object state)
{
Expand Down