Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is "java.io.IOException:Connection reset by peer" thrown?

ERROR GServerHandler  - java.io.IOException: Connection reset by peer java.io.IOException: Connection reset by peer         at sun.nio.ch.FileDispatcher.read0(Native Method)         at sun.nio.ch.SocketDispatcher.read(Unknown Source)         at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)         at sun.nio.ch.IOUtil.read(Unknown Source)         at sun.nio.ch.SocketChannelImpl.read(Unknown Source)         at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:323)         at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:282)         at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:202)         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)         at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)         at java.lang.Thread.run(Unknown Source) 

This log is from a game server implemented using netty. What can cause this exception ?

like image 603
WorM Avatar asked Dec 28 '11 15:12

WorM


People also ask

What does Java IOException Connection reset by peer mean?

java.io.IOException: Connection reset by peer = The other side has abruptly aborted the connection in midst of a transaction.

What is Connection reset by peer?

Connection Reset by peer means the remote side is terminating the session. This error is generated when the OS receives notification of TCP Reset (RST) from the remote server.

What causes Java IO IOException?

IOException is thrown when an error occurred during an input-output operation. That can be reading/writing to a file, a stream (of any type), a network connection, connection with a queue, a database etc, pretty much anything that has to do with data transfer from your software to an external medium.


2 Answers

java.io.IOException: Connection reset by peer

The other side has abruptly aborted the connection in midst of a transaction. That can have many causes which are not controllable from the server side on. E.g. the enduser decided to shutdown the client or change the server abruptly while still interacting with your server, or the client program has crashed, or the enduser's internet connection went down, or the enduser's machine crashed, etc, etc.

like image 100
BalusC Avatar answered Oct 07 '22 11:10

BalusC


To expand on BalusC's answer, any scenario where the sender continues to write after the peer has stopped reading and closed its socket will produce this exception, as will the peer closing while it still had unread data in its own socket receive buffer. In other words, an application protocol error. For example, if you write something to the peer that the peer doesn't understand, and then it closes its socket in protest, and you then continue to write, the peer's TCP stack will issue an RST, which results in this exception and message at the sender.

like image 33
user207421 Avatar answered Oct 07 '22 11:10

user207421