springboot整合redis一直报远程主机强迫关闭了一个现有的连接
2024-04-28 06:54:20 - INFO - [oEventLoop-4-7] io.lettuce.core.protocol.CommandHandler . log 219 : null Unexpected exception during request: java.io.IOException: 远程主机强迫关闭了一个现有的连接。
java.io.IOException: 远程主机强迫关闭了一个现有的连接。
at sun.nio.ch.SocketDispatcher.read0(Native Method) ~[na:1.8.0_201]
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43) ~[na:1.8.0_201]
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223) ~[na:1.8.0_201]
at sun.nio.ch.IOUtil.read(IOUtil.java:192) ~[na:1.8.0_201]
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380) ~[na:1.8.0_201]
at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:247) ~[netty-buffer-4.1.43.Final.jar:4.1.43.Final]
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1147) ~[netty-buffer-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148) ~[netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700) [netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635) [netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552) [netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514) [netty-transport-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1050) [netty-common-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [netty-common-4.1.43.Final.jar:4.1.43.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [netty-common-4.1.43.Final.jar:4.1.43.Final]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_201]
需要修改一下2处,好像timeout 默认就是0,tcp-keepalive默认就是300,那为什么还回报错呢?可能是启动的时候没有指定配置文件
当一个客户端空闲N秒后关闭连接(0表示禁用)
119 # Close the connection after a client is idle for N seconds (0 to disable)
120 timeout 0
如果非0每隔配置的时间就给客户端发送ack,这么做有两个原因(简言之一个是探活,另一个是保持链接)
in absence of communication怎么理解???chatgpt给出的解释是"如果客户端暂停发送请求或者网络中断了,Redis服务端也会给客户端发送ack"
122 # TCP keepalive.
123 #
124 # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
125 # of communication. This is useful for two reasons:
126 #
127 # 1) Detect dead peers.
128 # 2) Force network equipment in the middle to consider the connection to be
129 # alive.
130 #
131 # On Linux, the specified value (in seconds) is the period used to send ACKs.
132 # Note that to close the connection the double of the time is needed.
133 # On other kernels the period depends on the kernel configuration.
134 #
135 # A reasonable value for this option is 300 seconds, which is the new
136 # Redis default starting with Redis 3.2.1.
137 tcp-keepalive 300
重启redis服务