-
Notifications
You must be signed in to change notification settings - Fork 740
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/3.1] Memory Leak in Microsoft.Extensions.Caching.Memory when handling exceptions #3535
Conversation
Note dotnet/runtime#42355 still has feedback that needs to be applied. |
@Tratcher the compiler doesn't like the shorter
Will apply the rest |
Feedback has been applied |
There has been some changes in the original PR, please make sure this PR is updated with those changes. |
Believe I now have everything except the shorter syntax for |
… handling exceptions (dotnet/extensions#3535) * Memory Leak in Microsoft.Extensions.Caching.Memory when handling exceptions * Fixup * Fixup * Fix another memory leak when one cache depends on another cache\n\nCommit migrated from dotnet/extensions@5dc3e89
Resolves #3533
Backport of dotnet/runtime#42355
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.