您好我是Netty的新手,因为我刚刚从一位同事手中接过了netty定制项目。对不起,如果之前已经询问(我已经搜索过)。我们的Netty版本为4.0.14
。
我一直在IllegalReferenceCountException
channel.writeAndFlush(response);
所以我在Netty中添加了一些调试打印输出,似乎对writeAndFlush netty的同一调用可能会多次释放(ByteBuf)response.content()。这是一个在4.0.14之后已经修复的已知问题,还是我使用它错了?
我的调试打印在下面。 ByteBuf的保留/释放有四次被调用。
发布(refCnt 1->0)
,然后是保留(refCnt 0->1)
,然后是版本(1->0)
和版本(0->-1)
:
1 - > 0 | io.netty.buffer.AbstractReferenceCountedByteBuf.release 142 | io.netty.handler.codec.http.DefaultFullHttpResponse.release 79 | io.netty.util.ReferenceCountUtil.release 68 | io.netty.handler.codec.MessageToMessageEncoder.write 91 | io.netty.handler.codec.MessageToMessageCodec.write 116 | io.netty.channel.DefaultChannelHandlerContext.invokeWrite 645 | io.netty.channel.DefaultChannelHandlerContext.write 699 | io.netty.channel.DefaultChannelHandlerContext.write 638 | io.netty.handler.timeout.IdleStateHandler.write 265 | io.netty.channel.DefaultChannelHandlerContext.invokeWrite 645 | io.netty.channel.DefaultChannelHandlerContext.access $ 2000 29 | io.netty.channel.DefaultChannelHandlerContext $ WriteTask.run 906 | io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks 354 | io.netty.channel.nio.NioEventLoop.run 353 | io.netty.util.concurrent.SingleThreadEventExecutor $ 2.run 101 | java.lang.Thread.run 745
0 - > 1 | io.netty.buffer.AbstractReferenceCountedByteBuf.retain 99 | io.netty.buffer.CompositeByteBuf.retain 1570 | io.netty.buffer.CompositeByteBuf.retain 40 | io.netty.handler.codec.http.HttpObjectEncoder.encodeAndRetain 165 | io.netty.handler.codec.http.HttpObjectEncoder.encode 92 | io.netty.handler.codec.MessageToMessageEncoder.write 89 | io.netty.channel.CombinedChannelDuplexHandler.write 193 | io.netty.channel.DefaultChannelHandlerContext.invokeWrite 645 | io.netty.channel.DefaultChannelHandlerContext.write 699 | io.netty.channel.DefaultChannelHandlerContext.write 638 | io.netty.handler.codec.MessageToMessageEncoder.write 115 | io.netty.handler.codec.MessageToMessageCodec.write 116 | io.netty.channel.DefaultChannelHandlerContext.invokeWrite 645 | io.netty.channel.DefaultChannelHandlerContext.write 699 | io.netty.channel.DefaultChannelHandlerContext.write 638 | io.netty.handler.timeout.IdleStateHandler.write 265 | io.netty.channel.DefaultChannelHandlerContext.invokeWrite 645 | io.netty.channel.DefaultChannelHandlerContext.access $ 2000 29 | io.netty.channel.DefaultChannelHandlerContext $ WriteTask.run 906 | io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks 354 | io.netty.channel.nio.NioEventLoop.run 353 | io.netty.util.concurrent.SingleThreadEventExecutor $ 2.run 101 | java.lang.Thread.run 745
1 - > 0 | io.netty.buffer.AbstractReferenceCountedByteBuf.release 142 | io.netty.handler.codec.http.DefaultFullHttpResponse.release 79 | io.netty.util.ReferenceCountUtil.release 68 | io.netty.handler.codec.MessageToMessageEncoder.write 91 | io.netty.channel.CombinedChannelDuplexHandler.write 193 | io.netty.channel.DefaultChannelHandlerContext.invokeWrite 645 | io.netty.channel.DefaultChannelHandlerContext.write 699 | io.netty.channel.DefaultChannelHandlerContext.write 638 | io.netty.handler.codec.MessageToMessageEncoder.write 115 | io.netty.handler.codec.MessageToMessageCodec.write 116 | io.netty.channel.DefaultChannelHandlerContext.invokeWrite 645 | io.netty.channel.DefaultChannelHandlerContext.write 699 | io.netty.channel.DefaultChannelHandlerContext.write 638 | io.netty.handler.timeout.IdleStateHandler.write 265 | io.netty.channel.DefaultChannelHandlerContext.invokeWrite 645 | io.netty.channel.DefaultChannelHandlerContext.access $ 2000 29 | io.netty.channel.DefaultChannelHandlerContext $ WriteTask.run 906 | io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks 354 | io.netty.channel.nio.NioEventLoop.run 353 | io.netty.util.concurrent.SingleThreadEventExecutor $ 2.run 101 | java.lang.Thread.run 745
0 - > -1 | io.netty.buffer.AbstractReferenceCountedByteBuf.release 142 | io.netty.util.ReferenceCountUtil.release 68 | io.netty.channel.ChannelOutboundBuffer.safeRelease 509 | io.netty.channel.ChannelOutboundBuffer.remove 294 | io.netty.channel.ChannelOutboundBuffer.failFlushed 448 | io.netty.channel.AbstractChannel $ AbstractUnsafe.flush0 684 | io.netty.channel.nio.AbstractNioChannel $ AbstractNioUnsafe.flush0 271 | io.netty.channel.AbstractChannel $ AbstractUnsafe.flush 651 | io.netty.channel.DefaultChannelPipeline $ HeadHandler.flush 1038 | io.netty.channel.DefaultChannelHandlerContext.invokeFlush 675 | io.netty.channel.DefaultChannelHandlerContext.flush 656 | io.netty.channel.ChannelOutboundHandlerAdapter.flush 115 | io.netty.channel.CombinedChannelDuplexHandler.flush 198 | io.netty.channel.DefaultChannelHandlerContext.invokeFlush 675 | io.netty.channel.DefaultChannelHandlerContext.flush 656 | io.netty.channel.ChannelDuplexHandler.flush 117 | io.netty.channel.DefaultChannelHandlerContext.invokeFlush 675 | io.netty.channel.DefaultChannelHandlerContext.flush 656 | io.netty.channel.ChannelDuplexHandler.flush 117 | io.netty.channel.DefaultChannelHandlerContext.invokeFlush 675 | io.netty.channel.DefaultChannelHandlerContext.access $ 1600 29 | io.netty.channel.DefaultChannelHandlerContext $ WriteTask.run 908 | io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks 354 | io.netty.channel.nio.NioEventLoop.run 353 | io.netty.util.concurrent.SingleThreadEventExecutor $ 2.run 101 | java.lang.Thread.run 745