You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enable Sentry Profiler Integration via AddProfilerIntegration()
Deploy to production for real scale workload
Watch memory climb until OOM issues
Expected Result
It shouldn't :P
Actual Result
We seem to have found memory leaks in the Sentry Profiler integration added via AddProfilingIntegration() due to relying on Microsoft.Diagnostics.Tracing.Etlx. The cause seems to be from undisposed instances of TraceLog, with several gigabytes of call stacks accumulating over the period of roughly an hour for us, eventually causing process memory starvation and crashes.
Without a minimal reproducible example, it's very difficult to say what might be happening.
Deploy to production for real scale workload
Specifically this... would be very hard to guess at. What about your production scale workloads is necessary for the problem to manifest? We'd just be stabbing in the dark trying to recreate this here.
👋 Thanks for the report! We've added the Needs Reproduction label because we need a minimal reproduction to investigate further.
Please provide a link to a public GitHub repository that reproduces the issue with as little code as possible. Our repro guide has tips on how to create one.
Some quick hints:
Start from a fresh dotnet new console (or similar) project
Add only the Sentry NuGet package(s) relevant to the bug
Include the exact SDK version number and your SentrySdk.Init / UseSentry call (with the DSN blanked out)
Alternatively, if the issue only manifests in your own codebase, you could try gradually removing code until you have a minimal repro.
Can confirm that, we had tried profiling with asp.net core back in January, in production it was eating ram. I'll try find some memory dumps before oom, will attach a bit later.
Thanks @kanadaj. Nothing from that line of code jumps out at me. What are you seeing as a leak (i.e. what isn't being released)?
According to the memory dump I have, the event handler's lambda method's compiler generated closure class itself is retained for some reason?
I think it might be because of the circular reference, since the scope event handler method references the middleware instance, and the middleware instance references the scope.
Probably need to change that method to be an instance method and unsubscribe it at the end of the request (or when the middleware is disposed of with IDisposable)
I think it might be because of the circular reference, since the scope event handler method references the middleware instance, and the middleware instance references the scope.
Circular references shouldn't be an issue for GC... as long as none of the roots reference any of the objects in the object graph, the GC should clean these up.
This is what I'm seeing after running your repro for about 75s (I did force a GC shortly before taking the snapshots, to make sure I wasn't seeing any false positives due to a lazy GC):
So nothing relevant I don't think.
I think we should merge the PR we already have, since that definitely addresses some confirmed memory leaks. Maybe we open a new issue if we think there are still issues from there.
@kanadaj let me know if you've still got issues even with 6.3.3 when this is available... we can create a new issue referencing the relevant comments from this one.
Just following up to say version 6.4.0 is available now. Would be great to know how this affects things for you and whether we need to keep digging or not:
Activity
linear-code commentedon Apr 2, 2026
NET-650
jamescrosswell commentedon Apr 6, 2026
Hi @kanadaj ,
Without a minimal reproducible example, it's very difficult to say what might be happening.
Specifically this... would be very hard to guess at. What about your production scale workloads is necessary for the problem to manifest? We'd just be stabbing in the dark trying to recreate this here.
github-actions commentedon Apr 6, 2026
👋 Thanks for the report! We've added the
Needs Reproductionlabel because we need a minimal reproduction to investigate further.Please provide a link to a public GitHub repository that reproduces the issue with as little code as possible. Our repro guide has tips on how to create one.
Some quick hints:
dotnet new console(or similar) projectSentrySdk.Init/UseSentrycall (with the DSN blanked out)Alternatively, if the issue only manifests in your own codebase, you could try gradually removing code until you have a minimal repro.
tvardero commentedon Apr 8, 2026
Can confirm that, we had tried profiling with asp.net core back in January, in production it was eating ram. I'll try find some memory dumps before oom, will attach a bit later.
13 remaining items
kanadaj commentedon Apr 15, 2026
@jamescrosswell Another memory leak seems to be from https://github.com/getsentry/sentry-dotnet/blob/main/src/Sentry.AspNetCore/SentryMiddleware.cs#L134 at least according to the memory dump we have. It's not a massive amount but a leaked handler is a leaked handler and should be removed during Scope cleanup
jamescrosswell commentedon Apr 15, 2026
Thanks @kanadaj. Nothing from that line of code jumps out at me. What are you seeing as a leak (i.e. what isn't being released)?
kanadaj commentedon Apr 15, 2026
According to the memory dump I have, the event handler's lambda method's compiler generated closure class itself is retained for some reason?
I think it might be because of the circular reference, since the scope event handler method references the middleware instance, and the middleware instance references the scope.
Probably need to change that method to be an instance method and unsubscribe it at the end of the request (or when the middleware is disposed of with IDisposable)
jamescrosswell commentedon Apr 15, 2026
Circular references shouldn't be an issue for GC... as long as none of the roots reference any of the objects in the object graph, the GC should clean these up.
This is what I'm seeing after running your repro for about 75s (I did force a GC shortly before taking the snapshots, to make sure I wasn't seeing any false positives due to a lazy GC):
So nothing relevant I don't think.
I think we should merge the PR we already have, since that definitely addresses some confirmed memory leaks. Maybe we open a new issue if we think there are still issues from there.
jamescrosswell commentedon Apr 15, 2026
@kanadaj let me know if you've still got issues even with 6.3.3 when this is available... we can create a new issue referencing the relevant comments from this one.
I'll kick off a new release now.
jamescrosswell commentedon Apr 17, 2026
Just following up to say version 6.4.0 is available now. Would be great to know how this affects things for you and whether we need to keep digging or not: