-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
SentryEvent memory leak with large exception object graphs #2516
Comments
Hey @danports and thanks for raising this! |
Sure thing: https://github.com/danports/MemoryLeakTest To run the repro project, you'll need to supply a valid DSN and MySQL connection string in If you run the repro project as is, you'll see memory usage increase almost monotonically and indefinitely (though it will increase slowly for the first minute or so while it is creating all of the initial database entries); however, if you comment out the
I think my initial theory is incorrect, since based on the Sentry debug logs, the posted event isn't all that large, and it is ingested correctly by the Sentry backend. So I'm not sure what the issue is - perhaps Sentry is hanging on to posted events for some reason? |
Huge thanks for the repro! We'll look into this. |
It looks like this may be a memory leak internal to the It looks like the runtime issue is mono/mono#19665 with a potential fix that was rejected as causing other problems: dotnet/runtime#48296. I'm not sure if there is a way for Sentry to work around this issue, or if we'd have to wait for a solution to the runtime problem. |
It looks like I may be able to work around this problem to some degree on my end. When the |
The workaround I described earlier has been effective in my use case, so I'll leave it to you guys to decide whether it's worth working around this in the Sentry codebase (e.g. by avoiding use of the leaky |
Depending on what functionality we're using from |
@Dominent are you disabling Sentry or just the profiling integration? Are you also seeing a memory leak and, if so, are you also using Quartz and MySQL? |
Looking into this further, I can reproduce the problem and, even though in theory it should only exist on Mono, we're seeing it in net7.0. To double check, I hacked together a ConcurrentQueueLite which, despite all it's performance shortcomings, does not have the same memory leak problem. Options at this stage:
|
On another (perhaps unrelated) note: I can also create a memory leak if I change the implementation of the public bool TryPeek([NotNullWhen(true)] out T? item)
{
throw new NotImplementedException();
} Initially this made me think the memory leak might occur any time an exception was thrown and caught here. However, if I put a breakpoint there it never gets triggered when using |
This issue was reported as fixed from version 4.6.0 but I still get the same issue after upgrading packages. |
Hey @mrhocuong, could you possibly give us some more information about how you use Sentry and what issues you see with memory consumption? |
I can also confirm that this issue is still happening for me, memory rises continuously with profiling enabled in my project. I'm using version 4.8.0 of both the SDK and the profiling package. Removing the profiling integration seems to clear up the memory issues immediately.
|
Thanks for reaching out and letting us know! |
Package
Sentry
.NET Flavor
.NET Core
.NET Version
7.0
OS
Linux
SDK Version
3.34.0
Self-Hosted Sentry Version
No response
Steps to Reproduce
I'm having an issue where a process in which I've enabled the Sentry Microsoft.Extensions.Logging integration is consistently leaking memory. The issue seems to be most obvious in cases where the
SentryEvent
exception instance references a large object graph - say, aMicrosoft.EntityFrameworkCore.DbUpdateConcurrencyException
that references aDbContext
with a large number of entities loaded.Expected Result
I would expect the
SentryEvent
instances to be processed/sent/etc. and eventually freed.Actual Result
Based on the process memory consumption (and memory dumps) it seems like the

SentryEvent
instances are never freed:I'm wondering if the Sentry SDK is trying to serialize and send the
DbUpdateConcurrencyException
along with everything in the associatedDbContext
, fails due to limitations on event size, and ends up retrying forever.A typical
gcroot
fromdotnet-dump analyze
looks like this:The text was updated successfully, but these errors were encountered: