Seems like memory leak
EvgenyGrishnov opened this issue · 2 comments
Good day. Can't figure out where exactly this happens.
How to reproduce
Create some .NET5 console app with BackgroundService
` protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
_bus = new BuiltinHandlerActivator();
_bus .Handle(_apiNotifier.Process);
Configure.With(_bus)
.Logging(l => l.None())
.Transport(t =>
{
var builder = t.UseRabbitMq("amqp://localhost:5672/localdev", "MyQueue");
builder.Prefetch(10);
})
.Options(o =>
{
o.SetNumberOfWorkers(2);
o.SetMaxParallelism(10);
})
.Start();
return Task.CompletedTask;
}`
Then just run debug and watch diagnostic tools "Process Memory" or JetBrains dotMemory profile.
Made a small program that just ran idle and let it run for a good hour or two - resulted in the following heap snapshot:
(and total memory usage seemed to creep consistently upwards – started around 40 MB, passed 60 MB after about 1 hour, even quite a few spontaneous GCs)
Unless I am reading this wrong, it looks like looks of cancellation-related things are being left on the heap.
If anyone happens to know what can cause a heap snapshot to look like this, feel free to chime in 🙂
I've pushed Rebus.RabbitMq 7.3.4 to NuGet.org now. In it, I've made it block on receive, as it seemed from the memory snapshot above that loads and loads of OperationCancelledExceptions were not being collected - hopefully, the new, blocking way of receiving will not result in memory rising that that.
I've been running the same program as the one above with the debugger attached for almost 30 minutes now, and memory usage hasn't risen above 27 MB. I'll leave it running until tomorrow morning just to see if it works as it should.
Thanks for reporting this issue 🙂