wangzihaogithub / spring-boot-protocol

springboot功能扩充-netty动态协议,可以支持各种网络协议的动态切换(单端口支持多个网络协议).支持mmap,sendfile零拷贝,http请求批量聚合
https://zihaoapi.cn
Apache License 2.0
117 stars 63 forks source link

大佬,出现NettyX-Server-Worker-Epoll这个问题是啥原因呀? #36

Closed QianCYang closed 4 months ago

QianCYang commented 4 months ago

[NettyX-Server-Worker-Epoll-4-4] c.g.n.p.s.DispatcherChannelHandler : handler exception. case=io.netty.channel.unix.Errors$NativeIoException: recvAddress(..) failed: Connection reset by peer, channel=[id: 0xd09192e2, L:/192.123.1.78:5783 - R:/192.168.90.187:56221]

wangzihaogithub commented 4 months ago

tcp连上后,读内容的过程中,tcp连接被对方close了 有可能是数据没传完,对方就关闭浏览器了。 或者客户端触发超时,直接close tcp连接了

wangzihaogithub commented 4 months ago

我下个版本,把这类异常去掉

QianCYang commented 4 months ago
java.net.SocketException: Connection reset
    at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:401) ~[na:na]
    at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:434) ~[na:na]
    at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:259) ~[netty-buffer-4.1.86.Final.jar:4.1.86.Final]
    at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1132) ~[netty-buffer-4.1.86.Final.jar:4.1.86.Final]
    at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:357) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:553) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.86.Final.jar:4.1.86.Final]
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.86.Final.jar:4.1.86.Final]
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.86.Final.jar:4.1.86.Final]
    at java.base/java.lang.Thread.run(Thread.java:1583) ~[na:na]
    at com.github.netty.core.util.NettyThreadX.run(NettyThreadX.java:50) ~[classes/:na]

我在本地idea 启动了com.github.netty.http.HttpBootstrap 这个测试Springboot项目 然后另一个项目 通过 String forObject = restTemplate.getForObject("http://localhost:8080/test/hello?name=xiaowang", String.class);访问

随着另一个项目的关闭会出现上面的报错,报错率是100%的

QianCYang commented 4 months ago

java.net.SocketException: Connection reset at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:401) ~[na:na] at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:434) ~[na:na] at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:259) ~[netty-buffer-4.1.86.Final.jar:4.1.86.Final] at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1132) ~[netty-buffer-4.1.86.Final.jar:4.1.86.Final] at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:357) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final] at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final] at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final] at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:553) ~[netty-transport-4.1.86.Final.jar:4.1.86.Final] at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.86.Final.jar:4.1.86.Final] at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.86.Final.jar:4.1.86.Final] at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.86.Final.jar:4.1.86.Final] at java.base/java.lang.Thread.run(Thread.java:1583) ~[na:na] at com.github.netty.core.util.NettyThreadX.run(NettyThreadX.java:50) ~[classes/:na]

我在本地idea 启动了com.github.netty.http.HttpBootstrap 这个测试Springboot项目 然后另一个项目 通过 String forObject = restTemplate.getForObject("http://localhost:8080/test/hello?name=xiaowang", String.class);访问

随着另一个项目的关闭会出现上面的报错,报错率是100%的

wangzihaogithub commented 4 months ago

你客户端项目的 restTemplate的ClientHttpRequestFactory , 应该用的是长链接的, 然后客户端项目shutdown时候,可能没有来得及执行完ClientHttpRequestFactory.destroy() 或shutdown。

wangzihaogithub commented 4 months ago

项目的关闭时,你应该还有正在读数据的请求还没执行完

wangzihaogithub commented 4 months ago

这个错误没影响,tomcat也有这个错误,应该log级别比较低,所以平时不会注意。

QianCYang commented 4 months ago

哦哦哦,好的

QianCYang commented 4 months ago

image 可以通过啥配置避免出现该问题吗?我这边一出现就是一大堆哦

QianCYang commented 4 months ago

image 可以通过啥配置避免出现该问题吗?我这边一出现就是一大堆哦

是这样处理吗? image

wangzihaogithub commented 4 months ago

我是这样改的

       if (cause.getClass().getName().startsWith("io.netty.handler.codec.http2")) {
                  // ignore
              } else if (IOException.class.isAssignableFrom(cause.getClass())) {
                  if (logger.isDebugEnabled()) {
                      logger.debug("handler IOException. case={}, channel={}", cause.toString(), context.channel(), cause);
                  }
              } else {
                  logger.warn("handler exception. case={}, channel={}", cause.toString(), context.channel(), cause);
              }
wangzihaogithub commented 4 months ago

已经在2.3.19解决

https://github.com/wangzihaogithub/spring-boot-protocol/pull/38