85
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 ?

Naman
  • 27,789
  • 26
  • 218
  • 353
WorM
  • 1,115
  • 1
  • 12
  • 18
  • 7
    I guess the wizard of the coast casted a spella gainst you so every single io operation you do will fail. Provide the code which cause the exception otherwise we will not be abel to help you – andreapier Dec 28 '11 at 16:01
  • 1
    Well, the client has rejected/closed the connection. You'd need the client logs to see what was the cause. – Thomas Dec 28 '11 at 16:01
  • 1
    @andreapier since, this exception seems to be network related, I can not provide the source code. thanks for the answer (and the joke) though – WorM Dec 28 '11 at 16:07

8 Answers8

93

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
23

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.

user207421
  • 305,947
  • 44
  • 307
  • 483
3

java.io.IOException in Netty means your game server tries to send data to a client, but that client has closed connection to your server.

And that exception is not the only one! There're several others. See BadClientSilencer in Xitrum. I had to add that to prevent those errors from messing my log file.

OM Bharatiya
  • 1,840
  • 14
  • 23
Ngoc Dao
  • 1,501
  • 3
  • 18
  • 27
  • 1
    It doesn't mean only that, and it isn't confined to just Netty either. – user207421 Jul 25 '12 at 06:13
  • 1
    I don't understand. WorM posted the stack trace with a read operation but all answers explain writing problem. – Daniil Iaitskov Oct 25 '13 at 05:58
  • Link not working. This one is: [BadClientSilencer](https://github.com/xitrum-framework/xitrum/blob/master/src/main/scala/xitrum/handler/inbound/BadClientSilencer.scala). Helped me! – mxro Apr 08 '16 at 07:41
1

java.io.IOException: Connection reset by peer

In my case, the problem was with PUT requests (GET and POST were passing successfully).

Communication went through VPN tunnel and ssh connection. And there was a firewall with default restrictions on PUT requests... PUT requests haven't been passing throughout, to the server...

Problem was solved after exception was added to the firewall for my IP address.

ognjenkl
  • 1,407
  • 15
  • 11
0

If this happens when using Rider, when building a Docker container. Make sure all you changes are pushed to git, delete your local repo and clone everything again to start from a fresh state. This might have to do with file permissions being messed up but this fixed it immediately for me

Jason Landbridge
  • 968
  • 12
  • 17
-1

For me useful code witch help me was http://rox-xmlrpc.sourceforge.net/niotut/src/NioServer.java

// The remote forcibly closed the connection, cancel

// the selection key and close the channel.

    private void read(SelectionKey key) throws IOException {
            SocketChannel socketChannel = (SocketChannel) key.channel();

            // Clear out our read buffer so it's ready for new data
            this.readBuffer.clear();

            // Attempt to read off the channel
            int numRead;
            try {
                numRead = socketChannel.read(this.readBuffer);
            } catch (IOException e) {
                // The remote forcibly closed the connection, cancel
                // the selection key and close the channel.
                key.cancel();
                socketChannel.close();
                return;
            }

            if (numRead == -1) {
                // Remote entity shut the socket down cleanly. Do the
                // same from our end and cancel the channel.
                key.channel().close();
                key.cancel();
                return;
            }
...
Appz
  • 61
  • 2
-2

There are lot of factors , first see whether server returns the result, then check between server and client.

rectify them from server side first,then check the writing condition between server and client !

server side rectify the time outs between the datalayer and server from client side rectify the time out and number of available connections !

  • 2
    You could add some hint on how to "rectify" and do those "checks" to improve that answer. – m02ph3u5 Sep 11 '15 at 14:15
  • 1
    Hi http://stackoverflow.com/users/890537/m02ph3u5 1. server side , you could increase the time out between server and data source. 2. could improve the server session time out . 3.Could improve apache time out for request to server. 4.improving Keep Alive Timeout. – Vimalkumar Natarajan Sep 11 '15 at 16:52
  • He is getting the exception while reading from the server. Your answer doesn't make sense. – user207421 Jun 17 '16 at 12:51
-2

It can also mean that the server is completely inaccessible - I was getting this when trying to hit a server that was offline

My client was configured to connect to localhost:3000, but no server was running on that port.

Brad Parks
  • 66,836
  • 64
  • 257
  • 336
  • 1
    It can't mean that. You can't have a 'connection reset' error unless you can first have a connection. You got a connection *refused*. – user207421 Oct 14 '21 at 23:10