何时出现“java.io.IOException:连接由对等方重置”扔?

发布于 2024-12-23 13:34:49 字数 940 浏览 3 评论 0原文

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)

该日志来自使用netty实现的游戏服务器。什么会导致这个异常?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

愿与i 2024-12-30 13:34:49

java.io.IOException:连接被对等方重置

另一方在事务过程中突然中止连接。这可能有很多原因,这些原因是服务器端无法控制的。例如,最终用户决定关闭客户端或突然更改服务器,同时仍在与服务器交互,或者客户端程序崩溃,或者最终用户的互联网连接中断,或者最终用户的计算机崩溃,等等。

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.

甜味拾荒者 2024-12-30 13:34:49

为了扩展 BalusC 的答案,发送方在对等方停止读取并关闭其套接字后继续写入的任何情况都会产生此异常,就像对等方在其自己的套接字接收缓冲区中仍有未读数据时关闭一样。换句话说,应用程序协议错误。例如,如果您向对等方写入了对等方不理解的内容,然后它关闭了其套接字以示抗议,然后您继续写入,则对等方的 TCP 堆栈将发出 RST,这会导致此异常和消息在发件人处。

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.

天气好吗我好吗 2024-12-30 13:34:49

Netty 中的 java.io.IOException 意味着您的游戏服务器尝试向客户端发送数据,但该客户端已关闭与您的服务器的连接。

而且这个例外并不是唯一的一个!还有其他几个。请参阅 BadClientSilencer 在 Xitrum。我必须添加它以防止这些错误弄乱我的日志文件。

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.

滴情不沾 2024-12-30 13:34:49

java.io.IOException:连接被对等方重置

在我的例子中,问题出在 PUT 请求上(GET 和 POST 成功传递)。

通信通过 VPN 隧道和 ssh 连接。并且有一个对 PUT 请求默认限制的防火墙... PUT 请求尚未传递到服务器...

在将我的 IP 地址的异常添加到防火墙后问题得到解决。

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.

∝单色的世界 2024-12-30 13:34:49

如果在使用 Rider、构建 Docker 容器时发生这种情况。确保所有更改都推送到 git,删除本地存储库并再次克隆所有内容以从新状态开始。这可能与文件权限被搞乱有关,但这立即为我解决了这个问题

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

半葬歌 2024-12-30 13:34:49

对我来说有用的代码可以帮助我是 http://rox-xmlrpc.sourceforge.net /niotut/src/NioServer.java

// 远程强制关闭连接,取消

// 选择键并关闭通道。

    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;
            }
...

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;
            }
...
温馨耳语 2024-12-30 13:34:49

因素很多,首先看服务器是否返回结果,然后服务器和客户端之间检查。

先从服务器端纠正,然后检查服务器和客户端之间的写入情况!

服务器端纠正数据层和服务器之间的超时
从客户端纠正超时和可用连接数!

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 !

溺深海 2024-12-30 13:34:49

这也可能意味着服务器完全无法访问 - 我在尝试访问离线的服务器时收到此消息

我的客户端配置为连接到 localhost:3000,但该端口上没有运行服务器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文