2881099 / csredis

.NET Core or .NET Framework 4.0+ client for Redis and Redis Sentinel (2.8) and Cluster. Includes both synchronous and asynchronous clients.
MIT License
2.01k stars 414 forks source link

哨兵 Master 重新选举后出现 Connection was not opened #508

Open beckjin opened 5 months ago

beckjin commented 5 months ago

csreids 错误【172.21.96.2:6379/0】:Connection was not opened at CSRedis.Internal.IO.RedisIO.GetOrThrow[T](T obj) at CSRedis.Internal.IO.RedisIO.get_Stream() at CSRedis.Internal.IO.RedisIO.Write(Byte[] data) at CSRedis.Internal.RedisConnector.Call[T](RedisCommand1 command) at CSRedis.RedisClient.Write[T](RedisCommand1 command) at CSRedis.RedisClient.HGet(String key, String field) at CSRedis.CSRedisClient.<>cDisplayClass207_0.b0(Object`1 c, String k) at CSRedis.CSRedisClient.<>cDisplayClass53_0`1.b0(Object1 conn) at CSRedis.CSRedisClient.GetAndExecute[T](RedisClientPool pool, Func2 handler, Int32 jump, Int32 errtimes)

System.Exception: Redis Sentinel Master is switching:Connection was not opened at CSRedis.CSRedisClient.GetAndExecute[T](RedisClientPool pool, Func2 handler, Int32 jump, Int32 errtimes) at CSRedis.CSRedisClient.ExecuteScalar[T](String key, Func3 hander) at CSRedis.CSRedisClient.Exists(String key)

2881099 commented 5 months ago

可以尝试 FreeRedis

beckjin commented 4 months ago

【172.21.96.3:26379/0】Status unavailable, waiting for recovery. Connection refused at FreeRedis.Internal.ObjectPool.ObjectPool1.GetFree(Boolean checkAvailable) at FreeRedis.Internal.ObjectPool.ObjectPool1.Get(Nullable1 timeout) at FreeRedis.RedisClient.PoolingAdapter.GetRedisSocket(CommandPacket cmd) at FreeRedis.RedisClient.PubSub.Subscribe(Boolean psub, Boolean ssub, String[] channels, Action3 handler) at FreeRedis.RedisClient.Subscribe(String channel, Action2 handler) at FreeRedis.RedisClient.SentinelAdapter..ctor(RedisClient topOwner, ConnectionStringBuilder sentinelConnectionString, String[] sentinels, Boolean rw_splitting) at FreeRedis.RedisClient..ctor(ConnectionStringBuilder sentinelConnectionString, String[] sentinels, Boolean rw_splitting) at MD.Redis.Free.FreeRedisHelper.CreateFreeRedisClient(RedisOptions options) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()n--- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()n--- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) Connection refusedr at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)n--- End of stack trace from previous location --- at System.Threading.Tasks.TaskToApm.End(IAsyncResult asyncResult) at FreeRedis.Internal.DefaultRedisSocket.Connect() at FreeRedis.Internal.DefaultRedisSocket.Write(CommandPacket cmd) at FreeRedis.RedisClient.SingleInsideAdapter.<>c__DisplayClass5_01.b__0() at FreeRedis.RedisClient.LogCallCtrl[T](CommandPacket cmd, Func1 func, Boolean aopBefore, Boolean aopAfter) at FreeRedis.RedisClient.LogCall[T](CommandPacket cmd, Func1 func) at FreeRedis.RedisClient.SingleInsideAdapter.AdapterCall[TValue](CommandPacket cmd, Func2 parse) at FreeRedis.RedisClient.Call(CommandPacket cmd) at FreeRedis.Internal.RedisClientPoolPolicy.PrevReheatConnectionPool(ObjectPool1 pool, Int32 minPoolSize)"}

FreeRedis 情况类似。我们模拟的情况是直接把某个实例所在的服务器关掉。

beckjin commented 4 months ago

情况基本与 https://github.com/2881099/FreeRedis/issues/180 一致