无法通过 StackExchange.Redis 重新连接到 Azure Redis

Can't reconnect to Azure Redis via StackExchange.Redis

警告:好吧,这是一个奇怪的地方,我不确定 SO 是否是正确的地方。

我有一个连接到 Azure Redis 缓存实例的 Azure 网站。 (使用 StackExchange.Redis)

一切都很好,然后有一天 - 网站无法连接到 Redis。

错误:

It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING

这是我的连接字符串:

mycache.redis.cache.windows.net,ssl=true,password=xxxxxx,syncTimeout=5000

这是我的诊断步骤:

  1. 尝试从本地连接到 Azure Redis。结果:成功(所以代码很好?)
  2. 尝试启动新的 Azure Redis 实例,从 Azure 连接。结果:失败(网站无法连接到任何 azure Redis 实例?)
  3. 启动新的 Azure 网站,代码与错误代码相同,指向现有的 Redis 缓存。结果:成功(嗯,什么?)
  4. 归档新的 MVC 网站,添加 StackExchange.Redis,部署到新的 Azure 网站,连接到 Redis。结果:成功(那么 Redis 好用吗?)
  5. 将 vanilla MVC 网站部署到 现有 Azure 网站(与 4 相同的代码,连接到相同的 Redis,唯一的区别是它使用旧的 Azure 物理网站 machine/networking).结果:失败 (wtf??)

所以 - 我认为 Redis 有 "blacklisted" Azure 网站? (这甚至可能吗?)我知道 client(我的代码)不会尝试继续重新连接,但我已经多次退回该网站,但它就是做不到重新连接到 Redis。

使用 相同代码 连接到 相同 Redis 实例的 new Azure 网站的事实 结果成功,告诉我 Azure/Redis 中出现了某种 blacklisting/routing 问题。

有什么想法吗?

编辑

看起来问题出在 Azure VNET 上。当我的网站是 Azure 虚拟网络的一部分时,它无法连接到 Redis。但是当我把它 out 从网络中取出时,它连接正常。在今天之前,此设置运行良好。

所以我想知道 Azure 是否进行了更改,使 VNET 中的网站无法连接到 Azure Redis? (我知道这毫无意义)

编辑 2:

附件是 Redis 连接尝试的日志。

Exception: It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING connection-string-removed:6380,password=password-removed,ssl=True Connecting connection-string-removed:6380/Interactive... BeginConnect: connection-string-removed:6380 1 unique nodes specified Requesting tie-break from connection-string-removed:6380

__Booksleeve_TieBreak... Allowing endpoints 00:00:05 to respond... Awaiting task completion, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=4,Free=32763,Min=1,Max=32767) Not all tasks completed cleanly, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=5,Free=32762,Min=1,Max=32767) connection-string-removed:6380 did not respond Awaiting task completion, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=5,Free=32762,Min=1,Max=32767) Not all tasks completed cleanly, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=5,Free=32762,Min=1,Max=32767) connection-string-removed:6380 failed to nominate (WaitingForActivation) No masters detected connection-string-removed:6380: Standalone v2.0.0, master; keep-alive: 00:01:00; int: Connecting; sub: Connecting; not in use: DidNotRespond connection-string-removed:6380: int ops=0, qu=2, qs=0, qc=0, wr=0, socks=1; sub ops=0, qu=0, qs=0, qc=0, wr=0, socks=1 Circular op-count snapshot; int: 0 (0.00 ops/s; spans 10s); sub: 0 (0.00 ops/s; spans 10s) Sync timeouts: 0; fire and forget: 0; last heartbeat: -1s ago resetting failing connections to retry... retrying; attempts left: 2... 1 unique nodes specified Requesting tie-break from connection-string-removed:6380 > __Booksleeve_TieBreak... Allowing endpoints 00:00:05 to respond... Awaiting task completion, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=6,Free=32761,Min=1,Max=32767) Not all tasks completed cleanly, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=7,Free=32760,Min=1,Max=32767) connection-string-removed:6380 did not respond Awaiting task completion, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=7,Free=32760,Min=1,Max=32767) Not all tasks completed cleanly, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=7,Free=32760,Min=1,Max=32767) connection-string-removed:6380 failed to nominate (WaitingForActivation) No masters detected connection-string-removed:6380: Standalone v2.0.0, master; keep-alive: 00:01:00; int: Connecting; sub: Connecting; not in use: DidNotRespond connection-string-removed:6380: int ops=0, qu=2, qs=0, qc=0, wr=0, async=3, socks=2; sub ops=0, qu=0, qs=0, qc=0, wr=0, socks=2 Circular op-count snapshot; int: 0 (0.00 ops/s; spans 10s); sub: 0 (0.00 ops/s; spans 10s) Sync timeouts: 0; fire and forget: 0; last heartbeat: -1s ago resetting failing connections to retry... retrying; attempts left: 1... 1 unique nodes specified Requesting tie-break from connection-string-removed:6380 > __Booksleeve_TieBreak... Allowing endpoints 00:00:05 to respond... Awaiting task completion, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=8,Free=32759,Min=1,Max=32767) EndConnect: connection-string-removed:6380 (socket shutdown) Connect complete: connection-string-removed:6380 All tasks completed cleanly, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=11,Free=32756,Min=1,Max=32767) connection-string-removed:6380 faulted: SocketFailure on PING Awaiting task completion, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=11,Free=32756,Min=1,Max=32767) Not all tasks completed cleanly, IOCP: (Busy=0,Free=1000,Min=1,Max=1000), WORKER: (Busy=7,Free=32760,Min=1,Max=32767) connection-string-removed:6380 failed to nominate (WaitingForActivation) No masters detected connection-string-removed:6380: Standalone v2.0.0, master; keep-alive: 00:01:00; int: Connecting; sub: Connecting; not in use: DidNotRespond connection-string-removed:6380: int ops=0, qu=2, qs=0, qc=0, wr=0, async=7, socks=3; sub ops=0, qu=0, qs=0, qc=0, wr=0, socks=3 Circular op-count snapshot; int: 0 (0.00 ops/s; spans 10s); sub: 0 (0.00 ops/s; spans 10s) Sync timeouts: 0; fire and forget: 0; last heartbeat: -1s ago

谁能破译这个?

我在 Azure Web Apps 团队工作 - 看起来你的 VNET 进入了一个特别奇怪的状态,并且正在中断你的应用程序的网络连接。我已修复此行为。

对于给您带来的不便,我们深表歉意...

我们可能遇到了同样的问题。我能够在没有虚拟网络的情况下将测试应用程序放到 Azure 中的 Web 应用程序上,并且它开箱即用(使用 Stackexchange.Redis)。当我将相同的代码放入作为虚拟网络一部分的 Web 应用程序时,它不起作用。

我通过将 AbortOnConnectFail 设置为 false 设法修复了第一个错误 ("It was not possible to connect to the redis server(s)..")。然后我收到错误 "No connection is available to service this operation: EXISTS foo"(= 在这种情况下试图检查密钥 'foo' 是否存在)。

我也可以通过将 ConnectTimeout 设置为 10 秒来解决这个问题。所以基本上,我 可以 让它工作,但是当(我假设) SE.Redis 失去连接并尝试重新连接时,这似乎会导致长时间的延迟。

如果以上帖子没有帮助,您可以检查:

  • 仔细检查您的密码(私钥)是否正确
  • 如果您的应用程序是可执行的,请尝试 check/uncheck 在项目属性中选择“首选 32 位”。
  • 尝试从 Azure redis 端(从 ui)关闭 ssl 并尝试将 useSsl 设置为 false。
  • 下载源代码(从那里:https://github.com/StackExchange/StackExchange.Redis)并尝试调试内部问题。

部分操作帮助了我。