问题描述

客户端使用 Lettuce.io 连接 Azure Redis,出现了长达15分钟的Timeout异常。

问题解答

Azure Redis作为PaaS服务,由于一些平台的升级操作而引发的故障转移(Failover)。 如Redis的客户端时部署在Linux服务器上,则可能导致长达15分钟无法重新连接的问题。

某些 Linux 版本中的默认 TCP 设置可能会导致 Redis 服务器连接失败 13 分钟或更长时间。 默认设置可以防止客户端应用程序检测关闭的连接,并在连接未正常关闭的情况下防止自动还原这些关闭的连接。

如果网络连接中断或 Redis 服务器脱机进行计划外维护,重新建立连接可能会失败。

目前Lettuce社区已知问题,在server端未发RST断开服务的场景下,Lettuce自恢复需要15+分钟的时间。https://github.com/lettuce-io/lettuce-core/issues/2082

目前已知有效的方式是修改linux tcp_retries参数,https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-best-practices-connection#tcp-settings-for-linux-hosted-client-applications

此外,Lettuce社区也有一些解决方案,https://github.com/lettuce-io/lettuce-core/issues/2082#issuecomment-1407609439

附录: Connection does not re-establish for 15 minutes when running on Linux

Connection stalls lasting for 15 minutes like this are often caused by very optimistic default TCP settings in some Linux distros (confirmed on CentOS so far). When a server stops responding without gracefully closing the connection, the client TCP stack will continue retransmitting packets for 15 minutes before declaring the connection dead and allowing the StackExchange.Redis reconnect logic to kick in.

With Azure Cache for Redis, it's fairly easy to reproduce this by rebooting nodes as mentioned above. In this case, the machine goes down abruptly and the Redis server isn't able to transmit a FIN packet to the client. The client TCP stack continues retransmitting on the same socket hoping the server will come back up. Even when the node has rebooted and come back, it has no record of that connection so it continues ignoring the client. If the client gave up and created a NEW connection, it would be able to resume communication with the server much sooner than 15 minutes.

As you found, there are TCP settings you can change on the client machine to force it to timeout the connection sooner and allow for reconnect. In addition to tcp_retries2, you can try tuning the keepalive settings as discussed here: lettuce-io/lettuce-core#1428 (comment). It should be safe to reduce these timeouts to more realistic durations machine-wide unless you have systems that actually depend on the unusually long retransmits.

An additional approach is using the ForceReconnect pattern recommended in the Azure best practices. If you're seeing issues like this, it's perfectly appropriate to trigger reconnect on RedisTimeoutExceptions in addition to RedisConnectionExceptions. Just don't be too aggressive with it because an overloaded server can also result in persistent RedisTimeoutExceptions. Recreating connections in that situation can cause additional server load and a cascade failure.

Unfortunately there's not much the StackExchange.Redis library can do about this situation, because the Linux TCP stack is hiding the lost connection. Detecting the stall at the library level would require making assumptions that would almost certainly lead to false positives in some scenarios. Instead, it's better for the client application to implement some detection/reconnection logic based on what it knows about its load and latency patterns.

【Azure Redis】Redis客户端出现15分钟的超时异常的更多相关文章

  1. Redis数据类型简介(十分钟快速学习Redis)

    如何在ubuntu18.04上安装和保护redis 如何连接到Redis数据库 如何管理Redis数据库和Keys 如何在Redis中管理副本和客户端 如何在Redis中管理字符串 如何在Redis中 ...

  2. 【Azure Redis 缓存 Azure Cache For Redis】Redis出现 java.net.SocketTimeoutException: Read timed out 异常

    问题描述 在使用Azure Redis时,遇见Read Timed out异常, Redis的客户端使用的时jedis.问题发生时,执行redis部分指令出错,大部分get指令,set指令能正常执行. ...

  3. redis web 客户端工具 redis-admin

    redis-admin是基于java的redis web客户端(redis client),以方便广大程序员使用redis为宗旨,集五种数据结构增删改查于一身. https://github.com/ ...

  4. 在使用Redis的客户端连接工具ServiceStack.Redis要注意的问题

    在使用Redis的客户端连接工具ServiceStack.Redis要注意的问题   Redis是一个非常NB的内存级的数据库,我们可以把很多”热数据“(即读写非常多的数据)放入其中来操作,这样就减少 ...

  5. Redis C客户端API - God's blog - 博客频道 - CSDN.NET

    Redis C客户端API - God's blog - 博客频道 - CSDN.NET Redis安装步骤: 1.redis server安装 wget http://redis.googlecod ...

  6. 【原创】自己动手写一个能操作redis的客户端

    引言 redis大家在项目中经常会使用到.官网也提供了多语言的客户端供大家操作redis,如下图所示 但是,大家有思考过,这些语言操作redis背后的原理么?其实,某些大神会说 只要按照redis的协 ...

  7. 推荐一个好的Redis GUI 客户端工具

    推荐一个好的Redis GUI 客户端工具 Redis Desktop Manager  

  8. Redis基于客户端分片的集群案例(待实践)

    说明: 下面的示例基本都是基于Linux去实现,目的是为了环境的统一,以便于把性能调整到最优.且基于Java.建议生产环境不要使用Windows/Mac OS这些. 在Java领域,基于客户端进行分片 ...

  9. redis可视化客户端

    1. 场景描述 redis安装完成后,使用命令行看还是有点不方便,github上有开源的redis可视化客户端,很好用,介绍下. 2.解决方案 使用redisclient客户端,来操作redis. 2 ...

  10. 自荐RedisViewer有情怀的跨平台Redis可视化客户端工具

    # **自荐一个有情怀的跨平台Redis可视化客户端工具——RedisViewer**[转载自 最美分享Coder 2019-09-17 06:31:00](https://www.toutiao.c ...

随机推荐

  1. pytest.ini配置文件

    pytest.ini文件是pytest框架独有的配置文件,主要作用就是在运行pytest.main时可指定运行顺序,也 就相当于在Terminal输入pytest+参数+路径效果一致,下面介绍几种简单 ...

  2. 机器学习从入门到放弃:卷积神经网络CNN(一)

    一.前言 在上一篇中我们使用全连接网络,来构建我们的手写数字图片识别应用,取得了很好的效果.但是值得注意的是,在实验的最后,最后我们无论把 LOSS 优化到如何低,似乎都无法在测试数据集 test d ...

  3. vue数据更新后在视图上不响应

    一.vue如何追踪变化 当你把一个普通的JS对象传给vue实例的data选项时, vue将遍历此对象的所有属性, 并使用 Object.defineProperty 把这些属性全部转为 getter/ ...

  4. 【K哥爬虫普法】微信公众号爬虫构成不正当竞争,爬虫er面对金山,如何避免滥用爬虫?

    我国目前并未出台专门针对网络爬虫技术的法律规范,但在司法实践中,相关判决已屡见不鲜,K 哥特设了"K哥爬虫普法"专栏,本栏目通过对真实案例的分析,旨在提高广大爬虫工程师的法律意识, ...

  5. CentOS7环境下MySQL的主从配置

    CentOS7环境下MySQL的主从配置 一.什么叫主从复制 通过在主服务器和从服务器之间切分处理客户查询的负荷,可以得到更好的客户响应时间.通俗点说就是select查询发送到从服务器,修改数据的语句 ...

  6. (C语言)每日代码||2023.12.25||strcpy()函数两个参数中的'\0'

    #include <stdio.h> #include <string.h> #define MAX 500 void test() { char arr1[] = { '1' ...

  7. 关于SUPPLEMENTAL_LOG_DATA_MIN的设置问题

    Oracle数据库开启附加日志,用于Logminer或基于Logminer的一些操作. 客户咨询关于开启附加日志,SUPPLEMENTAL_LOG_DATA_MIN显示为啥是implicit,如何改成 ...

  8. 《ASP.NET Core 与 RESTful API 开发实战》-- (第7章)-- 读书笔记(上)

    第 7 章 高级主题 7.1 缓存 缓存是一种通过存储资源的备份,在请求时返回资源备份的技术.ASP.NET Core 支持多种形式的缓存,既支持基于 HTTP 的缓存,也支持内存缓存和分布式缓存,还 ...

  9. .NET Core开发实战(第17课:为选项数据添加验证:避免错误配置的应用接收用户流量)--学习笔记

    17 | 为选项数据添加验证:避免错误配置的应用接收用户流量 三种验证方法 1.直接注册验证函数 2.实现 IValidateOptions 3.使用 Microsoft.Extensions.Opt ...

  10. 听说有 Hugging Face 陪伴的春节,是这样的…

    辞旧迎新春节到,家家户户好热闹.Hugging Face 中国团队成员祝各位社区成员们新春快乐,万事如意! 过去的一年我们持续看到 AI 技术的腾飞和发展,以及诸多机构为开源 AI 作出巨大的贡献.非 ...