Skip to content

Commit

Permalink
fix fail-fast+2nd level retry bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mookid8000 committed Mar 21, 2024
1 parent 56d3b7d commit 2a940ff
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@
## 8.2.2
* Add optional `rbs2-delivery-count` header, which may be provided by transports that are capable of counting deliveries natively

## 8.2.3
## 8.2.4
* Fix behavior of fail-fast combined with 2nd level retries to be like before (i.e. failing fast will immediately trigger 2nd level retry)

---
Expand Down
28 changes: 28 additions & 0 deletions Rebus.Tests/Bugs/FailFastStillInvokesSecondLevelRetries.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using Rebus.Activation;
Expand Down Expand Up @@ -47,6 +48,33 @@ public async Task ItWorksAsIndicatedByTheNameOfThisTestFixture()

}

[Test]
public async Task SecondLevelRetryAfterFailFastExceptionStillHasTheCaughtExceptions()
{
var events = new ConcurrentQueue<string>();

using var activator = new BuiltinHandlerActivator();

activator.Handle<string>(async _ => throw new FailFastException("wooH00"));

activator.Handle<IFailed<string>>(async failed => events.Enqueue($"Tracker had {failed.Exceptions.Count()} exceptions"));

var bus = Configure.With(activator)
.Transport(t => t.UseInMemoryTransport(new(), "whatever"))
.Options(o => o.RetryStrategy(secondLevelRetriesEnabled: true))
.Start();

await bus.SendLocal("🙂");

await events.WaitUntil(e => e.Count >= 1);

Assert.That(events, Is.EqualTo(new[]
{
"Tracker had 1 exceptions",
}));

}

[Test]
public async Task WhatHappensIfSecondLevelHandlerThrowsFailFastToo()
{
Expand Down
3 changes: 2 additions & 1 deletion Rebus/Retry/Simple/DefaultRetryStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public async Task Process(IncomingStepContext context, Func<Task> next)
: $"Received message with native delivery count header value = {deliveryCount} thus exceeding MAX number of delivery attempts ({maxDescription}) – the error tracker did not provide additional information about the errors, which may/may not be because the errors happened on another Rebus instance.";

var exceptionInfo = _exceptionInfoFactory.CreateInfo(new RebusApplicationException(exceptionMessage));
await PassToErrorHandler(context, GetAggregateException(new[] {exceptionInfo}.Concat(exceptions)));
await PassToErrorHandler(context, GetAggregateException(new[] { exceptionInfo }.Concat(exceptions)));
await _errorTracker.CleanUp(messageId);
transactionContext.SetResult(commit: false, ack: true);

Expand Down Expand Up @@ -130,6 +130,7 @@ async Task HandleException(Exception exception, ITransactionContext transactionC
// special case - it we're supposed to fail fast, AND 2nd level retries are enabled, AND this is the first delivery attempt, try to dispatch as 2nd level:
if (_retryStrategySettings.SecondLevelRetriesEnabled)
{
await _errorTracker.RegisterError(messageId, exception);
await DispatchSecondLevelRetry(transactionContext, messageId, context, next);
return;
}
Expand Down

0 comments on commit 2a940ff

Please sign in to comment.