【问题标题】:netty java.io.IOException: Connection reset by peer caused by RST,ACKnetty java.io.IOException:由 RST、ACK 引起的对等连接重置
【发布时间】:2016-11-18 05:55:34
【问题描述】:

我们使用haproxy来做负载均衡,netty服务器不断升"java.io.IOException: Connection reset by peer" 下面是异常堆栈:

java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
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:379)
at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288)
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1055)
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:245)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:112)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:510)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:467)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:381)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
at java.lang.Thread.run(Thread.java:745)

我使用tcpdump转储netty服务器的网络数据,见下文

10.125.137.11,10.125.137.13,10.125.137.14是hapxory服务器ip 似乎 haproxy 只是发送 [RST,ACK] 来完成健康检查。

所以,我想知道我是否必须在我的处理程序中处理这种情况(比如检查异常是 IOException,忽略它,因为日志中充满了这个异常),还是应该由 netty 自己处理?

【问题讨论】:

    标签: netty haproxy ioexception


    【解决方案1】:

    如果 HAProxy 发送 RST,则它是预期的。如果您不关心,您可以通过覆盖exceptionCaught(...) 方法来过滤ChannelHandler 实现中的异常。

    【讨论】:

    • 我已经考虑过了,但我担心如果我只是忽略 IOException,也许同样的真实错误也会被忽略
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多