gateway java.io.IOException: 你的主机中的软件中止了一个已建立的连接。
java.io.IOException: 你的主机中的软件中止了一个已建立的连接。at sun.nio.ch.SocketDispatcher.read0(Native Method)Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:Error has been observed at the followi
[2022-10-17 10:43:29,455] [reactor-http-nio-8] [WARN ] r.netty.http.client.HttpClientConnect 294 -- [] [id: 0x07295210, L:/192.168.0.162:60388 - R:/192.168.0.162:9087] The connection observed an error
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.PooledByteBuf.setBytes(PooledByteBuf.java:253)
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1134)
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
[2022-10-17 10:43:29,455] [reactor-http-nio-8] [ERROR] o.s.b.a.w.r.e.AbstractErrorWebExceptionHandler 122 -- [] [667422d3] 500 Server Error for HTTP POST "接口路径"
java.io.IOException: 你的主机中的软件中止了一个已建立的连接。
at sun.nio.ch.SocketDispatcher.read0(Native Method)
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ org.springframework.web.cors.reactive.CorsWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ HTTP POST "接口路径" [ExceptionHandlingWebHandler]
Stack trace:
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.PooledByteBuf.setBytes(PooledByteBuf.java:253)
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1134)
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
根据在网上搜索到的结果,向配置文件中增加了如下配置,开发环境中暂未发现该问题复现,但是具体原因任不清楚。
//是否开启ssl协议
server.ssl.enabled=false
//最大空闲连接时间
spring.cloud.gateway.httpclient.pool.max-idle-time=10000
根据参考文章所述:
1.GateWay的max-idle-time:60000ms之后才释放连接,Server的connection-timeout在100ms(参考文章设置为100ms,默认值60000ms)之后就断开连接,此时GateWay会从连接池取已经断开的连接请求,以致报错。
2.因为Server是Provider, GateWay是Consumer,尽可能保证Consumer先于Provider断开连接,设置max-idle-time的时间小于connection-timeout。
网上查询了一下GateWay的max-idle-time相关内容,得到以下信息:
“设置连接的最大空闲时长为5秒(默认NULL:响应完成即可关闭),超时则关闭连接释放资源。 这个时长的设置要小于后端服务的连接超时时长,确保网关回收请求在后端服务回收请求之前完成。”
参考链接:
https://www.cnblogs.com/wftop1/p/15789238.html
https://www.javazhiyin.com/81492.html
更多推荐
所有评论(0)