Skip to content

Likely concurrency issue in CacheManager.Microsoft.Extensions.Caching.Memory #267

@jkernsva

Description

@jkernsva

Our application is occasionally getting into a state in which its MemoryCache will throw exceptions when used. Once in this state, all further requests will fail and we must restart the process to get it into a healthy state again.

We speculate that this is related to concurrent writes to one of its internal metadata structures. Here is a partial stack trace from one of the occurences:

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.Collections.Generic.HashSet`1.AddIfNotPresent(T value)
   at CacheManager.MicrosoftCachingMemory.MemoryCacheExtensions.RegisterChild(MemoryCache cache, Object parentKey, Object childKey)
   at CacheManager.MicrosoftCachingMemory.MemoryCacheHandle`1.AddInternalPrepared(CacheItem`1 item)
   at CacheManager.Core.BaseCacheManager`1.AddToHandles(CacheItem`1 item, Int32 foundIndex)
   at CacheManager.Core.BaseCacheManager`1.GetCacheItemInternal(String key, String region)
   at CacheManager.Core.BaseCacheManager`1.GetOrAddInternal(String key, String region, Func`3 valueFactory)

I have submitted a pull request, #266, that I believe will address this problem. We have been testing this build internally and we have not seen the issue reoccur.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions