Skip to content

Issue with ReThrowDistributedCacheExceptions #414

@kory-revivemedia

Description

@kory-revivemedia

Hello!

I'm noticing that when using .WithDefaultEntryOptions and specifying ReThrowDistributedCacheExceptions set to false, that I'm still seeing distributed cache exceptions rethrown and logged (i.e. ILogger.LogError). The default value of ReThrowDistributedCacheExceptions is set to false, but noticing that it's not always honored. I want to recategorize distributed cache errors as warnings and not have them bubble up as errors in our logs/monitoring as they usually can be safely ignored.

Here's an example exception that's thrown and logged. I manually spun down my local redis instance to simulate redis issues.

ZiggyCreatures.Caching.Fusion.FusionCacheDistributedCacheException: An error occurred while working with the distributed cache
 ---> StackExchange.Redis.RedisConnectionException: The message timed out in the backlog attempting to send because no connection became available (5000ms) - Last Connection Exception: It was not possible to connect to the redis server(s). ConnectTimeout, command=HMGET, timeout: 5000, inst: 0, qu: 1, qs: 0, aw: False, bw: CheckingForTimeout, last-in: 0, cur-in: 0, sync-ops: 0, async-ops: 643, serverEndpoint: localhost:6379, conn-sec: n/a, aoc: 0, mc: 1/1/0, mgr: 10 of 10 available, clientName: KORY-REVIVE(SE.Redis-v2.8.22.13109), IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=1,Free=32766,Min=22,Max=32767), POOL: (Threads=12,QueuedItems=0,CompletedItems=10613,Timers=20), v: 2.8.22.13109 (Please take a look at this article for some common client-side issues that can cause timeouts: https://stackexchange.github.io/StackExchange.Redis/Timeouts)
 ---> StackExchange.Redis.RedisConnectionException: It was not possible to connect to the redis server(s). ConnectTimeout
   --- End of inner exception stack trace ---
   at Microsoft.Extensions.Caching.StackExchangeRedis.RedisCache.GetAndRefreshAsync(String key, Boolean getData, CancellationToken token)
   at Microsoft.Extensions.Caching.StackExchangeRedis.RedisCache.GetAsync(String key, CancellationToken token)
   at ZiggyCreatures.Caching.Fusion.Internals.Distributed.DistributedCacheAccessor.<>c__DisplayClass14_0`1.<<TryGetEntryAsync>b__0>d.MoveNext() in /_/src/ZiggyCreatures.FusionCache/Internals/Distributed/DistributedCacheAccessor_Async.cs:line 165
--- End of stack trace from previous location ---
   at ZiggyCreatures.Caching.Fusion.Internals.RunUtils.RunAsyncFuncWithTimeoutAsync[TResult](Func`2 asyncFunc, TimeSpan timeout, Boolean cancelIfTimeout, Action`1 timedOutTaskProcessor, CancellationToken token) in /_/src/ZiggyCreatures.FusionCache/Internals/RunUtils.cs:line 43
   at ZiggyCreatures.Caching.Fusion.Internals.Distributed.DistributedCacheAccessor.TryGetEntryAsync[TValue](String operationId, String key, FusionCacheEntryOptions options, Boolean hasFallbackValue, Nullable`1 timeout, CancellationToken token) in /_/src/ZiggyCreatures.FusionCache/Internals/Distributed/DistributedCacheAccessor_Async.cs:line 164
   --- End of inner exception stack trace ---
   at ZiggyCreatures.Caching.Fusion.Internals.Distributed.DistributedCacheAccessor.TryGetEntryAsync[TValue](String operationId, String key, FusionCacheEntryOptions options, Boolean hasFallbackValue, Nullable`1 timeout, CancellationToken token) in /_/src/ZiggyCreatures.FusionCache/Internals/Distributed/DistributedCacheAccessor_Async.cs:line 187

When setting a breakpoint at the throw location, I see that the value of options.ReThrowDistributedCacheExceptions is true:

Image

Sample code that uses WithDefaultEntryOptions:

        services.AddFusionCache()
            .WithSystemTextJsonSerializer()
            .WithDistributedCache(CreateRedisCache())
            .WithRegisteredBackplane()
            .WithOptions(ConfigureFusionCacheOptions())
            .WithDefaultEntryOptions(options => { options.ReThrowDistributedCacheExceptions = false; });

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions