motan icon indicating copy to clipboard operation
motan copied to clipboard

关于Netty经常报Connection reset by peer问题

Open Succy opened this issue 6 years ago • 5 comments

最近排查线上异常日志的时候发现,Netty经常报Connection reset by peer或者timeout的问题,用的Motan版本是1.1.1,想请教一下,一般是什么样情况下会报这个问题,异常信息中又定位不到motan的堆栈信息,所以很迷惑。

主要异常信息如下:

java.io.IOException: Connection timed out
	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:380)
	at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288)
	at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1106)
	at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:343)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:123)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
	at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
	at java.lang.Thread.run(Thread.java:748)
2018-08-24 15:54:05 ERROR [ntLoopGroup-3-2] error       : NettyChannelHandler exceptionCaught: remote=/172.16.1.153:5429 local=/192.168.2.239:8
520 event=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:380)
	at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288)
	at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1106)
	at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:343)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:123)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
	at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
	at java.lang.Thread.run(Thread.java:748)

Succy avatar Aug 24 '18 08:08 Succy

有可能是网络原因,也有可能是client端因超时等原因关闭了链接

rayzhang0603 avatar Aug 27 '18 06:08 rayzhang0603

@rayzhang0603 我尝试将client端timeout调大点观察下

Succy avatar Aug 28 '18 10:08 Succy

connection reset by peer一般是对方关闭了连接导致,我猜你服务的对象大多是移动端吧

lhl4546 avatar Sep 06 '18 11:09 lhl4546

@lhl4546 我的客户端是在 Springboot里面调用,然后提供restful给前端调用,调整了客户端连接超时参数之后,稍微有点好转,但是情况还是存在。

Succy avatar Sep 10 '18 14:09 Succy

可能是客户端开启了长链接,但实际未支持,导致服务端尝试服用旧链接的时候报错

gogodjzhu avatar Nov 29 '21 06:11 gogodjzhu