我刚刚将Netty 3软件转换为5,但是遇到了问题。有了一个客户,一切都很好。我可以同时使用两个解码器(它们可以正确切换)并允许我登录。

当我尝试连接另一个客户端时,无论第一个客户端是否仍处于连接状态,该问题都会出现。第一个客户端保持连接完全正确,但是第二个客户端完全无法连接(不经过第一个解码器)。

Apr 26, 2015 4:51:16 AM io.netty.channel.ChannelHandlerInvokerUtil notifyOutboundHandlerException
WARNING: Failed to fail the promise because it's done already: DefaultChannelPromise@7f3386c4(failure(io.netty.util.IllegalReferenceCountException: refCnt: 0)
io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1
    at io.netty.buffer.AbstractReferenceCountedByteBuf.release(AbstractReferenceCountedByteBuf.java:111)
    at io.netty.util.ReferenceCountUtil.release(ReferenceCountUtil.java:84)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.write(AbstractChannel.java:791)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.write(DefaultChannelPipeline.java:1278)
    at io.netty.channel.ChannelHandlerInvokerUtil.invokeWriteNow(ChannelHandlerInvokerUtil.java:158)
    at io.netty.channel.DefaultChannelHandlerInvoker.invokeWrite(DefaultChannelHandlerInvoker.java:337)
    at io.netty.channel.PausableChannelEventExecutor.invokeWrite(PausableChannelEventExecutor.java:132)
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:539)
    at io.netty.handler.timeout.IdleStateHandler.write(IdleStateHandler.java:267)
    at io.netty.channel.ChannelHandlerInvokerUtil.invokeWriteNow(ChannelHandlerInvokerUtil.java:158)
    at io.netty.channel.DefaultChannelHandlerInvoker.invokeWrite(DefaultChannelHandlerInvoker.java:337)
    at io.netty.channel.PausableChannelEventExecutor.invokeWrite(PausableChannelEventExecutor.java:132)
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:539)
    at io.netty.channel.ChannelHandlerAdapter.write(ChannelHandlerAdapter.java:265)
    at io.netty.channel.ChannelHandlerInvokerUtil.invokeWriteNow(ChannelHandlerInvokerUtil.java:158)
    at io.netty.channel.DefaultChannelHandlerInvoker$WriteTask.run(DefaultChannelHandlerInvoker.java:440)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:328)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    at io.netty.util.internal.chmv8.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1412)
    at io.netty.util.internal.chmv8.ForkJoinTask.doExec(ForkJoinTask.java:280)
    at io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:877)
    at io.netty.util.internal.chmv8.ForkJoinPool.scan(ForkJoinPool.java:1706)
    at io.netty.util.internal.chmv8.ForkJoinPool.runWorker(ForkJoinPool.java:1661)
    at io.netty.util.internal.chmv8.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:126)


这是我的引导程序:

EventLoopGroup bossGroup = new NioEventLoopGroup();
        EventLoopGroup workerGroup = new NioEventLoopGroup();
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_REUSEADDR, true)
                .childOption(ChannelOption.SO_KEEPALIVE, true)
                .childOption(ChannelOption.TCP_NODELAY, true)
                .localAddress(43594)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ChannelPipeline p = ch.pipeline();
                        p.addLast("timeout", new IdleStateHandler(15, 0, 0));
                        p.addLast("decoder", new RS2Decoder());
                        p.addLast("handler", new ChannelHandler());
                    }
                }
        ).bind();


第一个解码器:

http://pastebin.com/9FWzXSVE

第二个解码器:

http://pastebin.com/n2D8RDgn

而我的频道处理程序:

http://pastebin.com/4mdXe5jV

最佳答案

解决方案是通过@Sharable批注将处理程序标记为可共享。

09-16 16:07