io.lettuce.core.protocol.CommandHandler - null Unexpected exception during request: java.io.IOException: 远程主机强迫关闭了一个现有的连接。 java.io.IOException: 远程主机强迫关闭了一个现有的连接。

一、报错信息

[2022-08-10 19:47:33.673] [lettuce-nioEventLoop-4-1] [INFO ] io.lettuce.core.protocol.CommandHandler - null Unexpected exception during request: java.io.IOException: 远程主机强迫关闭了一个现有的连接。
java.io.IOException: 远程主机强迫关闭了一个现有的连接。
	at sun.nio.ch.SocketDispatcher.read0(Native Method)
	at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
	at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
	at sun.nio.ch.IOUtil.read(IOUtil.java:192)
	at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
	at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288)
	at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1108)
	at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:347)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:628)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:563)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:480)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:442)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:745)
[2022-08-10 19:47:35.141] [localhost-startStop-2] [INFO ] o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@117e9283: startup date [Thu Jul 28 19:47:20 CST 2022]; root of context hierarchy
[2022-08-10 19:47:35.719] [lettuce-eventExecutorLoop-1-2] [INFO ] io.lettuce.core.protocol.ConnectionWatchdog - Reconnecting, last destination was localhost/127.0.0.1:6379
[2022-08-10 19:47:37.203] [localhost-startStop-2] [INFO ] o.s.context.support.DefaultLifecycleProcessor - Stopping beans in phase 2147483647
[2022-08-10 19:47:37.500] [localhost-startStop-2] [INFO ] o.s.jmx.export.annotation.AnnotationMBeanExporter - Unregistering JMX-exposed beans on shutdown
[2022-08-10 19:47:37.609] [localhost-startStop-2] [INFO ] o.s.jmx.export.annotation.AnnotationMBeanExporter - Unregistering JMX-exposed beans

 

二、原因

与Redis有关
io.lettuce.core.protocol.ConnectionWatchdog - Reconnecting, last destination was localhost/127.0.0.1:6379

  

三、解决方法

1、修改配置文件redis.windows.conf

参考:https://blog.csdn.net/lxyoucan/article/details/124816647
springboot 使用 lettuce做redis 的连接池,lettuce 调用netty
与redis服务器通讯。redis服务器的连接超时缺省是65,改为0后不再报上面的错。

客户端空闲 N 秒后关闭连接(0 表示禁用)
timeout 0

2、检查redis的链接配置是否正确

参考:https://www.codeleading.com/article/69143601144/
  redis:
    host: localhost
    port: 6379
    password: abc123
    database: 5
    timeout: 60s
      ## springboot2.0之后将连接池由jedis改为lettuce
    lettuce:
      pool:
        max-idle: 30
        max-active: 8
        max-wait: 10000
        min-idle: 10

同时在redis的配置文件redis.windows.conf中设置tcp-keepalive时间为60s(据说3.2.1默认为300),完成后重启redis

 

posted @ 2022-08-11 10:02  生活这把杀猪刀  阅读(5916)  评论(0编辑  收藏  举报