Skip to content

DictionaryHandle - sporadic NullReferenceException #167

@burnstek

Description

@burnstek

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.

06/14 15:42:40 - System.NullReferenceException: Object reference not set to an instance of an object.
   at CacheManager.Core.Internal.DictionaryCacheHandle`1.GetCacheItemInternal(String key, String region)
   at CacheManager.Core.Internal.DictionaryCacheHandle`1.GetCacheItemInternal(String key)
   at CacheManager.Core.Internal.BaseCache`1.GetCacheItem(String key)
   at CacheManager.Core.BaseCacheManager`1.GetCacheItemInternal(String key, String region)
   at CacheManager.Core.BaseCacheManager`1.GetCacheItemInternal(String key)
   at CacheManager.Core.Internal.BaseCache`1.GetCacheItem(String key)
   at CacheManager.Core.Internal.BaseCache`1.Get(String key)
   at CacheManager.Core.Internal.BaseCache`1.Get[TOut](String key)
   at DataCache.DataCacheClient.Get[T]() in 

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:

_cache = CacheFactory.Build(s => s
                .WithJsonSerializer()
                .WithDictionaryHandle()
                .WithExpiration(ExpirationMode.Absolute, TimeSpan.FromSeconds(60)) 
                .And
                .WithRedisConfiguration("redis", multiplexer, 1)
                .WithRedisCacheHandle("redis")
                .WithExpiration(ExpirationMode.Absolute, TimeSpan.FromSeconds(180))); 

And the test harness:

                        for (int j = 0; j < 100; j++) // test this N times.
                        {
                            new Thread(() =>
                            {
                                _cache.Get("some_key");
                            }).Start();
                        }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions