Java netty AbstractChannelHandlerContext invokeExceptionCaught

Java netty AbstractChannelHandlerContext invokeExceptionCaught

我最近在将我的 netty 库更新到 Netty 4 后发现了一个问题。 我是 运行 游戏服务器,每次玩家 "logs out" 以不正确的方式(即点击客户端上的 X 按钮,或者只是与服务器失去连接)时,服务器都会提示CMD 中的错误消息:

aug 29, 2015 8:38:01 PM io.netty.channel.AbstractChannelHandlerContext invokeExceptionCaught
WARNING: An exception was thrown by a user handler's exceptionCaught() method while handling the following exception:
java.io.IOException: De externe host heeft een verbinding verbroken
    at sun.nio.ch.SocketDispatcher.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 io.netty.buffer.UnpooledUnsafeDirectByteBuf.setBytes(UnpooledUnsafeDirectByteBuf.java:447)
    at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:881)
    at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:242)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:119)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
    at io.netty.util.concurrent.SingleThreadEventExecutor.run(SingleThreadEventExecutor.java:110)
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
    at java.lang.Thread.run(Unknown Source)

这是用于启动服务器网络的代码:

address = new InetSocketAddress(43594);
bootstrap = new ServerBootstrap();
bootstrap.childHandler(new NettyChannelInitializer());
bootstrap.channel(NioServerSocketChannel.class);
bootstrap.group(new NioEventLoopGroup());
bootstrap.bind(address);

如果有人能告诉我如何至少删除异常消息,我会很高兴:D。它不会给服务器或客户端带来任何进一步的问题,但它只会在每次发生时提示此警告

亲切的问候,亚历克斯

编辑:我的 NettyChannelInitializer class:

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;

public final class NettyChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {

        ch.pipeline().addLast("encoder", new RS2Encoder()).addLast("decoder", new RS2LoginProtocol()).addLast("handler", new NettyChannelHandler());
    }

}

您只需通过覆盖以下方法在您的处理程序(在您的 NettyChannelInitializer() 中创建)中捕获此异常:

void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception;