ServiceStack.Redis 与 Azure Redis 的连接问题



我在多个环境(即不同的Azure Redis实例)中遇到了问题,类似于这篇文章: ServiceStack.Redis: 无法连接: sPort:

但是,当然,我们无法移动或更改 redis 服务器,因为我们依赖于 Azure Redis。如果是延迟问题,我们可能会被搞砸...

我们使用的是旧版本的 SS (4.0.42.0),此后更新到最新版本 (4.0.56.0),并看到了相同的间歇性问题。

以下是一些背景: - 问题仅在至少 2K 请求(有时或多或少)后出现。是的,我们使用的是最新的 SS 许可证。 - 这是非常间歇性的,大多数请求都是成功的,但失败的请求通常会在小束(1-5 个左右)中失败,然后问题消失一段时间 - 我尝试过RedisPoolManager,PooledRedisClientManager,结果相同。 - 我已经为每个请求做了一个客户端统计信息报告,并确保池包含足够的客户端,没有错误等。我很少看到 40 个客户端一次使用超过 2-3 个。 -

不同的例外情况:- IOException消息Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host和堆栈跟踪,其中包括提及 RedisClient。这是完整的错误转储:
"exception": { "message": "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.", "source": "System", "targetSite": "Int32 Read(Byte[], Int32, Int32)", "stackTrace": " at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)rn at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)rn at System.Net.Security._SslStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)rn at System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)rn at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)rn at System.Net.Security.SslStream.Read(Byte[] buffer, Int32 offset, Int32 count)rn at System.IO.BufferedStream.ReadByte()rn at ServiceStack.Redis.RedisNativeClient.ReadLine()rn at ServiceStack.Redis.RedisNativeClient.ReadData()rn at ServiceStack.Redis.RedisClient.<>c__DisplayClass1c 1.b__1b(RedisClient r)\r at ServiceStack.Redis.RedisClient.Exec[T](Func 2 action)rn at ServiceStack.Redis.RedisClientManagerCacheClient.Get[T](String key)rn at API.ServiceInterface.RequestExtensions.GetUserSession(IRequest req, Boolean createIfNotExists) in F:\src\CCCAPI CD (DevLab)\ServiceInterface\Extensions\RequestExtensions.cs:line 26rn at API.WebHost.AuthImpl.HandleBlacklistedUserSessions(IRequest req, IResponse httpResponse) in F:\src\CCCAPI CD (DevLab)\WebHost\Authentication\AuthImpl.cs:line 30rn at ServiceStack.ServiceStackHost.ApplyPreRequestFilters(IRequest httpReq, IResponse httpRes)rn at ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName)", "type": "IOException", "innerException": { "message": "An existing connection was forcibly closed by the remote host", "source": "System", "targetSite": "Int32 Read(Byte[], Int32, Int32)", "stackTrace": " at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)", "type": "SocketException" } }

-我们看到的另一个例外是带有消息Unable to Connect: sPort: 50447的异常类型 ServiceStack.Redis(有趣的是,端口发生了变化,并且永远不是应该使用的真正Azure Redis SSL端口,似乎池管理器可能不会将正确的端口传递给此客户端?这是完整的转储: "exception": { "message": "Unable to Connect: sPort: 50447", "source": "ServiceStack.Redis", "targetSite": "ServiceStack.Redis.RedisException CreateConnectionError()", "stackTrace": " at ServiceStack.Redis.RedisNativeClient.CreateConnectionError()rn at ServiceStack.Redis.RedisNativeClient.SendExpectData(Byte[][] cmdWithBinaryArgs)rn at ServiceStack.Redis.RedisClient.<>c__DisplayClass1c 1.b__1b(RedisClient r)\r at ServiceStack.Redis.RedisClient.Exec[T](Func 2 action)rn at ServiceStack.Redis.RedisClientManagerCacheClient.Get[T](String key)rn at API.ServiceInterface.RequestExtensions.GetUserSession(IRequest req, Boolean createIfNotExists) in F:\src\CCCAPI CD (DevLab)\ServiceInterface\Extensions\RequestExtensions.cs:line 26rn at API.WebHost.AuthImpl.HandleBlacklistedUserSessions(IRequest req, IResponse httpResponse) in F:\src\CCCAPI CD (DevLab)\WebHost\Authentication\AuthImpl.cs:line 30rn at ServiceStack.ServiceStackHost.ApplyPreRequestFilters(IRequest httpReq, IResponse httpRes)rn at ServiceStack.Host.RestHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName)", "type": "RedisException", "innerException": { "message": "An existing connection was forcibly closed by the remote host", "source": "System", "targetSite": "Void Write(Byte[], Int32, Int32)", "stackTrace": " at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)", "type": "SocketException" }

我正在为此苦苦挣扎...任何帮助将不胜感激。

远程主机强行关闭了现有连接

这是一个一般的 TCP 网络错误,指示您的连接已被远程 redis 实例或潜在故障网络硬件终止,没有什么可以阻止它在客户端上发生,但应使用 ServiceStack.Redis 自动重试功能减轻其影响。

无法连接:端口:50447

sPort(源)是指客户端端口,

即在客户端上随机选择的用于建立TCP连接的TCP端口,它不是指连接字符串中指定的服务器(目标)端口。

该错误表示 Redis 客户端正在尝试建立新的 TCP 连接,但已被拒绝。客户端无能为力,只能继续重试。

鉴于问题在某些加载后出现的频率更高,这可能是服务器过度饱和的结果,在这种情况下,可以尝试增加正在使用的 Azure Redis 缓存的大小。

我一直注意到这些间歇性问题在 Azure 上似乎比其他任何地方都多(不清楚是由于受欢迎程度还是不可靠性),Redis 在其自然环境中通常是坚如磐石的,即在 Linux 上运行并从同一子网访问。可以尝试的另一种解决方案是在访问它的同一数据中心的 Linux VM 上运行 redis 服务器 - 这可能会绕过托管 Azure Redis 服务可能添加的任何限制或其他限制。

最新更新