-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[release/5.0-rc2] Memory Leak in Microsoft.Extensions.Caching.Memory when handling exceptions #42494
[release/5.0-rc2] Memory Leak in Microsoft.Extensions.Caching.Memory when handling exceptions #42494
Conversation
…ptions When an exception is thrown inside MemoryCache.GetOrCreate, we are leaking CacheEntry objects. This is because they are not being Disposed properly, and the async local CacheEntryStack is growing indefinitely. The fix is to ensure the CacheEntry objects are disposed correctly. In order to do this, I set a flag to indicate whether the CacheEntry.Value has been set. If it hasn't, Disposing the CacheEntry won't add it to the cache. Fix #42321
…inner cache's entries will reference the outer cache entries through the ScopeLease object. Null'ing out the CacheEntry._scope field when it is disposed fixes this issue.
Tagging subscribers to this area: @eerhardt, @maryamariyan |
@eerhardt -- did you send mail on this? |
No. I didn't know we needed to send mail. I thought we just update the top post with the template. |
I did now. The test failures are in System.Drawing, and System.Text.Json, which are unrelated to this change. |
Approved in email. Feel free to merge, @eerhardt. |
Backport of #42355 to release/5.0-rc2
/cc @eerhardt
Customer Impact
Customers reported a memory leak with MemoryCache. It’s possible to get leaks in two cases:
Testing
New unit tests were added for both scenarios.
Risk