-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
failing test: Microsoft.Extensions.Caching.Memory.CapacityTests.AddingReplacementExceedsCapacityRemovesOldEntry #45868
Comments
Tagging subscribers to this area: @eerhardt, @maryamariyan Issue DetailsFailing on PR: #45849 on
build: https://dnceng.visualstudio.com/public/_build/results?buildId=914578&view=results
|
@adamsitnik - any chance your recent changes to MemoryCache affected this? |
@eerhardt I can't reproduce it on my machine. I've looked at the source code and I'll try to reproduce it on my other machines |
The previous two failures are also on Nov 22, so quite some time in the past. |
@ChadNedzlek thank you for providing all the details! @eerhardt my first PR (#44797) got merged on the 17th of Nov, but it was a very low-risk change with just better inlining and I don't think that it could have introduced a bug. We should watch it closely and see if it reproduces more often (and in what config) |
It looks like there is a race with overcapacity compaction here runtime/src/libraries/Microsoft.Extensions.Caching.Memory/src/MemoryCache.cs Lines 186 to 192 in dcb6653
which runs on a threadpool runtime/src/libraries/Microsoft.Extensions.Caching.Memory/src/MemoryCache.cs Lines 454 to 461 in dcb6653
If the thread from the threadpool will remove the entry from the runtime/src/libraries/Microsoft.Extensions.Caching.Memory/src/MemoryCache.cs Lines 627 to 637 in dcb6653
|
@vonzshik thank you for the analysis (I haven't looked and confirmed it). Do you have any interest in working on a fix? Perhaps it is possible to create a test that with enough iterations and threads more often repros this locally. |
@danmoseley I can 'sorta' emulate reproduction by adding a few
ThreadPool.QueueUserWorkItem(s => ((MemoryCache)s!).OvercapacityCompaction(), this);
Thread.Sleep(1000);
Thread.Sleep(2000);
Interlocked.Add(ref _cacheSize, -entry.Size); But no luck without that yet (though I was running on .net 7 build in debug, might have a better luck with .net 6). I think the best fix here (which also should prove whether that's the actual issue I've found) is to lower the runtime/src/libraries/Microsoft.Extensions.Caching.Memory/tests/CapacityTests.cs Lines 284 to 287 in 24bbfbf
|
@maryamariyan I have updated frequency above -- it fails every couple of days on random PR in last month. |
Updated the milestone. Blocking clean CI issues cannot be future. |
Can confirm that this reproes consistently with the 2 sleeps suggested above.
|
Frequency during 4/1-7/22:
Failing on PR: #45849 on
net6.0-Linux-Debug-x64-CoreCLR_checked-Ubuntu.1804.Amd64.Open
, which IIUC, shouldn't be affected by the PR changes.build: https://dnceng.visualstudio.com/public/_build/results?buildId=914578&view=results
console: https://helixre8s23ayyeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-pull-45849-merge-bbac7bcbe2e74adca7/Microsoft.Extensions.Caching.Memory.Tests/console.e1720aa2.log?sv=2019-07-07&se=2020-12-29T20%3A30%3A56Z&sr=c&sp=rl&sig=f2gjogjMSfevE3okDjeWwFG4pv5G077HR4EMxg9k76o%3D
The text was updated successfully, but these errors were encountered: