You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
JunTaoLuo
changed the title
Flaky failures of Microsoft.Extensions.Caching.Memory.CacheEntryScopeExpirationTests.LinkContexts_AreThreadSafe
AddExpirationToken extension is not thread safe
Dec 28, 2016
The issue arises when AddExpirationToken is called from different threads concurrently. Since they operate on the underlying ExpirationTokens, an IList, is not thread safe, some tokens may not be added.
A few possible fixes (need to make sure this doesn't introduce other races/deadlocks):
Use ICollection.SyncRoot of the ExpirationTokens collection for synchronization.
There's already a lock object for each entry we can use for synchronization though it's not exposed. We can move this extension to the interface instead.
MakeExpirationTokens a thread safe collection
Should review handling of expiration tokens for other potential races.
I've noticed that
CacheEntryScopeExpirationTests.LinkContexts_AreThreadSafe
test can occasionally fail when run repeatedly at https://github.com/aspnet/Caching/blob/dev/test/Microsoft.Extensions.Caching.Memory.Tests/CacheEntryScopeExpirationTests.cs#L475.I will usually see one or two failures when repeating this test 50 times. I have reproduced this on Win10 x64 and Win10 x86.
cc @Tratcher
The text was updated successfully, but these errors were encountered: