Uh oh!
There was an error while loading. Please reload this page.
Memory Leak in Microsoft.Extensions.Caching.Memory when handling exceptions - #42355
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. Fixdotnet#42321
Dotnet-GitSync-Bot
commented
Sep 16, 2020
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
ghost
commented
Sep 16, 2020
Tagging subscribers to this area: @eerhardt, @maryamariyan |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
eerhardt
commented
Sep 17, 2020
I believe all current feedback has been addressed. I also renamed 2 variables to better describe what they are doing. PTAL. |
…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.
eerhardt
commented
Sep 19, 2020
/backport to release/5.0-rc2 |
Started backporting to release/5.0-rc2: https://github.com/dotnet/runtime/actions/runs/262733314 |
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