Redis链接池异常:io.lettuce.core.RedisException: io.netty.channel.unix.Errors $NativeIoException: syscall:read(…) failed: Connection reset by peer
一、现象
昨天项目刚上线,早上看到报警有告警,根据告警时间马上找到了报错日志如下:
org.springframework.data.redis.RedisSystemException: Redis exception; nested exception is io.lettuce.core.RedisException: io.netty.channel.unix.Errors
$NativeIoException: syscall:read(..) failed: Connection reset by peer
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:74)
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41)
at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
at org.springframework.data.redis.connection.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection.java:268)
at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.convertLettuceAccessException(LettuceStringCommands.java:799)
at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.set(LettuceStringCommands.java:148)
at org.springframework.data.redis.connection.DefaultedRedisConnection.set(DefaultedRedisConnection.java:274)
at org.springframework.data.redis.connection.DefaultStringRedisConnection.set(DefaultStringRedisConnection.java:946)
at org.springframework.data.redis.core.DefaultValueOperations$3.inRedis(DefaultValueOperations.java:240)
at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:59)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)
at org.springframework.data.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:236)
at com.yonghui.redis.utils.RedisUtils.set(RedisUtils.java:85)
看到io.lettuce.core.RedisException,马上我就想起了redis的链接池配置参数:
这肯定和redis的链接池有关系。
二、出现Connection reset by peer的原因
从网上资料来看,这个问题出现的原因应该是,在网络通信过程中,有网络断开的情况发生。
各种资料总结了会发生Connection reset by peer的情况 :
redis服务器和客户端的简单图解:

根据以上内容总结一下,大概有以下标红的点会发生问题:
三、解决方法
根据这几个推断,可以修改如下的redis配置:


四、优化后的结果对比


搜索日志中的错误信息,果然已经消失不见了。