AbortOnConnectFail does not work
Describe the bug Setting up a simple sample with AbortOnConnectFail set to false does not work (any sample will do). Simply set AbortOnConnectFail = false and an exception is thrown if the Redis server is not running.
To Reproduce Steps to reproduce the behavior:
- Create any sample application
- Set AbortOnConnectFail to false
- Turn off the Redis server or set the connection to an invalid host/port
- Try to hit the Redis server using the cache client
Expected behavior
- If the server is offline, a disconnected Multiplexer should be created and the request should gracefully fail
Desktop (please complete the following information):
- Runtime version .NET Framework, .NET Core 3.0
- Version 6.3.0
Exception sample:
StackExchange.Redis.RedisConnectionException: No connection is available to service this operation: SETEX TerminalLegacyCredentials:test; UnableToConnect on localhost:6379/Interactive, Initializing/NotStarted, last: NONE, origin: BeginConnectAsync, outstanding: 0, last-read: 2s ago, last-write: 2s ago, keep-alive: 60s, state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 0s ago, v: 2.0.601.3402; IOCP: (Busy=0,Free=1000,Min=12,Max=1000), WORKER: (Busy=1,Free=32766,Min=12,Max=32767), Local-CPU: n/a
---> StackExchange.Redis.RedisConnectionException: UnableToConnect on localhost:6379/Interactive, Initializing/NotStarted, last: NONE, origin: BeginConnectAsync, outstanding: 0, last-read: 2s ago, last-write: 2s ago, keep-alive: 60s, state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 0s ago, v: 2.0.601.3402
at StackExchange.Redis.TaskExtensions.TimeoutAfter(Task task, Int32 timeoutMs) in C:\projects\stackexchange-redis\src\StackExchange.Redis\TaskExtensions.cs:line 49
at StackExchange.Redis.ConnectionMultiplexer.WaitAllIgnoreErrorsAsync(Task[] tasks, Int32 timeoutMilliseconds, LogProxy log, String caller, Int32 callerLineNumber) in C:\projects\stackexchange-redis\src\StackExchange.Redis\ConnectionMultiplexer.cs:line 672
--- End of inner exception stack trace ---
at StackExchange.Redis.ConnectionMultiplexer.ThrowFailed[T](TaskCompletionSource`1 source, Exception unthrownException) in C:\projects\stackexchange-redis\src\StackExchange.Redis\ConnectionMultiplexer.cs:line 2201
--- End of stack trace from previous location where exception was thrown ---
at StackExchange.Redis.Extensions.Core.Implementations.RedisDatabase.AddAsync[T](String key, T value, TimeSpan expiresIn, When when, CommandFlags flag)
I haven't dug in deep enough to determine if this is the same issue or not, but we're encountering an issue where I am wondering if it's related. When a connection fails, we get a series of errors for "No connection is available to service this operation" with slightly different additional messaging above. StackExchange.Redis constructs an exception message indicating that abortConnect=false should be added to our configuration, but we already have it set in configuration. This message appears to be conditionally added by StackExchange.Redis when the property for abortConnect is set to true. So either we're losing configuration after a muxer connection failure, or configuration is somehow never set correctly to begin with.
We're also considering a best practice as suggested for Redis implementations and documented by Microsoft (https://docs.microsoft.com/en-us/azure/azure-cache-for-redis/cache-dotnet-core-quickstart) to implement a reconnection strategy for forced reconnect when a threshold is exceeded. However, it doesn't appear that the multiplexers in use by RedisCacheClient in these libraries are exposed in a way that would allow us to re-initialize and reconnect.
Can confirm AbortOnConnectFail does not work
Looks good here
https://github.com/imperugo/StackExchange.Redis.Extensions/blob/master/src/core/StackExchange.Redis.Extensions.Core/Configuration/RedisConfiguration.cs#L439
true, my bad @imperugo thanks!