Closed burnstek closed 7 years ago
I cannot reproduce the error at all. Running it on Windows 10 Fullframework and netstandard not on Linux.
Ok turns out I already fixed that part in a more recent check-in...
There was a potential race condition issue in line 127 where result
can be null if the TryRemove
returns false. That was a bug.
Will be fixed in the next patch release... sorry ;)
here is a more reliable way to reproduce it
var _cache = CacheFactory.Build(s => s
.WithDictionaryHandle()
.WithExpiration(ExpirationMode.Absolute, TimeSpan.FromMilliseconds(10))
.And
.WithDictionaryHandle()
.WithExpiration(ExpirationMode.Absolute, TimeSpan.FromMilliseconds(20))
.And
.WithDictionaryHandle()
.WithExpiration(ExpirationMode.Absolute, TimeSpan.FromMilliseconds(30))
.And
.WithDictionaryHandle()
.WithExpiration(ExpirationMode.Absolute, TimeSpan.FromMilliseconds(40))
.And
.WithDictionaryHandle()
.WithExpiration(ExpirationMode.Absolute, TimeSpan.FromMilliseconds(50))
);
_cache.OnRemoveByHandle += (s, a) =>
{
Console.Write(a.Level);
};
while (true)
{
Action act = () =>
{
try
{
var val = _cache.Get("some_key");
if (val == null)
{
_cache.Put("some_key", "value");
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
};
Parallel.Invoke(Enumerable.Repeat(act, 1000).ToArray());
}
fixed in 1.1.1
Hello! Rarely, we see this occur. I don't know the steps to repro, but it does happen from time to time. We can't repro with MemoryCacheHandle.
Looking at DictionaryCacheHandle.cs, I have no idea what could be going wrong. Apparently _cache is null on this line, but it's not clear at all how that could be.
if (_cache.TryGetValue(fullKey, out CacheItem<TCacheValue> result))
Here is a sample config I use to reproduce this:
And the test harness: