Consume is repeated indefinetely when raised OperationCancelledException
See original GitHub issueIs this a bug report?
Yes
Can you also reproduce the problem with the latest version?
Yes
Environment
- Operating system: Windows 10 Enterprise
- Visual Studio version: 2017, v15.9.8
- Dotnet version: NetCore SDK 2.2.104
Steps to Reproduce
- Bus configured with RabbitMQ transport
- Retry policy on ‘ReceiveEndpoint’ set to Immediate(1)
- Publish one event
- Consumer throws TaskCancellationException or OperationCancelledException
Expected Behavior
The system calls consumer trying to consume message, then retry policy reiterate it exactly one time (UseMessageRetry(r => r.Immediate(1)))
Actual Behavior
The system calls consumer trying to consume message without end. The same scenario with ‘InMemory’ transport works as we expected.
Reproducible Demo
public class Program
{
static void Main(string[] args)
{
var bus = Bus.Factory.CreateUsingRabbitMq(cfg =>
{
cfg.Host(new Uri("rabbitmq://localhost/"), h =>
{
h.Username("guest");
h.Password("guest");
});
cfg.ReceiveEndpoint("input-queue", e =>
{
e.UseMessageRetry(r => r.Immediate(1));
e.Consumer<MyConsumer>();
});
});
bus.Start();
bus.Publish(new SimpleEvent { Id = 123 });
Console.ReadLine();
}
}
public class MyConsumer : IConsumer<SimpleEvent>
{
public Task Consume(ConsumeContext<SimpleEvent> context)
{
var attempt = context.GetRetryAttempt();
throw new TaskCanceledException("task cancelled");
}
}
public class SimpleEvent
{
public int Id { get; set; }
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
c# - Using BlockingCollection<T>
When there are items in the queue and no limit such as BoundedCapacity or Empty has been reached then the producers and consumer...
Read more >Confusing Cancellation in BackgroundService · Issue #1245
At this point, I would expect the DerpService to see the cancellation, throw an OperationCanceledException , and thus pass the assertion.
Read more >Create Sophisticated Asynchronous Applications with ...
The Try…Catch block that catches my OperationCanceledException encloses all of my processing so that raising the Exception skips everything.
Read more >System.IO.Pipelines in .NET
PipeWriter.FlushAsync supports a way to cancel the current flush operation via PipeWriter.CancelPendingFlush without raising an exception.
Read more >Polly 7.2.4
All Polly policies are fully thread-safe. You can safely re-use policies at multiple call sites, and execute through policies concurrently on different threads....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thank you for quick response. What do you recommend to avoid infinite loop in case, that we actually faced, when consumer calls http api that is not accessible due to some network issue. I know, easy answer is to solve network issue, but still it could sometimes happen. What I missed in above ‘Reproducible Demo’ is that our abstraction over http client wraps exceptions.
This was addressed in v6.