-
Notifications
You must be signed in to change notification settings - Fork 13
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
Memory Leak after updating Akka from 1.5.27.1 to 1.5.37 #516
Comments
Ok I narrowed it down even further. The call stack that created the new objects is:
Due to the mention of Investigating the potential source differences between these two versions, it appears that the Query Throttling PR touched on several of these. I suspect that is a good candidate for the source of the memory leak. |
Thank you for the very detailed report @lucavice, we will look into this as soon as possible |
Moving the issue to this repo because it is not related to Akka.NET |
@lucavice, do you see any timeout exceptions thrown from your queries inside your logs? Either |
hey @Arkatufus. No, I don't see any exceptions inside my logs. For example, I am now running the system locally and I see about 1000 new objects created and not collected of type In case it helps, this is both happening locally using SQL Server and on Azure using Azure SQL Databases for querying the events. |
Hi @Arkatufus, I am able to replicate it on a super simple program that I prepared here: https://github.com/lucavice/AkkaNetBugRepro/tree/memory-leak/AkkaNetBugRepro That hopefully can help tracking it down. |
That's great! Thank you, I'll use a profiler on your reproduction to try and catch the problem. |
Thanks Luca - I took your code and built a self-contained reproduction here https://github.com/Aaronontheweb/AkkaPersistenceSqlMemoryLeak/ I can reproduce the issue! Going to see about trying to fix it next |
I am 99% sure the problem is how we're closing over the internal static async Task<T> ExecuteQueryWithTransactionAsync<T>(
this AkkaPersistenceDataConnectionFactory factory,
DbStateHolder state,
Func<AkkaDataConnection, CancellationToken, Task<T>> handler)
{
using var cts = CancellationTokenSource.CreateLinkedTokenSource(state.ShutdownToken);
{
cts.CancelAfter(state.QueryThrottleTimeout);
await state.QueryPermitter.Ask<QueryStartGranted>(RequestQueryStart.Instance, cts.Token);
}
try
{
return await factory.ExecuteWithTransactionAsync(state.IsolationLevel, state.ShutdownToken, handler);
}
finally
{
state.QueryPermitter.Tell(ReturnQueryStart.Instance);
}
} |
However, I have tried several permutations of this: {
// using var requestTimeout = new CancellationTokenSource(state.QueryThrottleTimeout);
// using var cts = CancellationTokenSource.CreateLinkedTokenSource(state.ShutdownToken, requestTimeout.Token);
await factory.QueryPermitter.Ask<QueryStartGranted>(RequestQueryStart.Instance, factory.QueryThrottleTimeout);
} Leak is still reproducible even with those - so the issue might be a higher level async chaining thing |
I think the issue here is I added a private build with some details here: Aaronontheweb/AkkaPersistenceSqlMemoryLeak#3 But basically, that the |
@lucavice so @Arkatufus found the source of the leak and it's from the PR you linked to - as it turns out, we've been calling I might need to open an issue on the general Akka.NET repo for this because that problem could occur anywhere |
Thanks for the update @Aaronontheweb. As I was trying to find the memory leak myself I was looking as well at that Just for my own understanding, is the reason why the |
I think it does merit an investigation in the main Akka.NET repo |
Version Information
Version of Akka.NET?
1.5.37
Which Akka.NET Modules?
Akka.NET + Persistence, Remoting, Clustering. Journal Plugin is Akka.Persistence.Sql
Describe the bug
Last week I updated our staging environment from Akka 1.5.27.1 to 1.5.37.
Spefically, I updated the following packages:
As part of this update, I also retargeted from .NET 7 to .NET 8.
After a few days, I noticed our staging environment running low on memory:
Inspecting the VMs reveal most of processes hosting Akka.NET were over 1GB in size.
The only exceptions were some processes that do not instantiate any journal reads, which were not affected. This may mean that the memory leak is coming from Akka.Persistence or the Akka.Persistence.Sql plugin.
Additionally, I took a memory dump of one of the affected processes:
Task<QueryStartGranted>
seems to be the culprit, which further indicates that the memory leak is coming from Akka.Persistence module or its plugin.Environment
Windows on .NET 8
Additional context
I am currently reverting our environment to 1.5.27.1 to verify that the memory leak disappears (just to confirm that this is not due to some other changes). Potentially, it could also be due to the upgrade to .NET 8, but probably less likely. I will monitor RAM usage and check back tomorrow to see if just reverting the packages version rollbacks the issue.
Let me know if there is anything else I can help with to narrow this down.
The text was updated successfully, but these errors were encountered: