Redis链接池异常:io.lettuce.core.RedisException: io.netty.channel.unix.Errors $NativeIoException: syscall:read(…) failed: Connection reset by peer

一、现象

昨天项目刚上线,早上看到报警有告警,根据告警时间马上找到了报错日志如下:

image-20210702153641105

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的链接池配置参数:

image-20210702153819216

这肯定和redis的链接池有关系。

二、出现Connection reset by peer的原因

从网上资料来看,这个问题出现的原因应该是,在网络通信过程中,有网络断开的情况发生。

各种资料总结了会发生Connection reset by peer的情况 :

image-20210702160654811

redis服务器和客户端的简单图解:

image-20210702160848932

根据以上内容总结一下,大概有以下标红的点会发生问题:

image-20210702161023225

三、解决方法

根据这几个推断,可以修改如下的redis配置:

image-20210702161152845 image-20210702161228567

四、优化后的结果对比

image-20210702161310591 image-20210702161353613

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

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐