2016-12-04 50 views
0

为什么以下内容被视为泄漏?即使发布之后Netty资源泄漏

2016-12-04 09:24:01,534 ERROR [epollEventLoopGroup-2-1] [io.netty.util.ResourceLeakDetector] - LEAK: ByteBuf.release() was not called before it's garbage-collected. See http://netty.io/wiki 
/reference-counted-objects.html for more information. 
Recent access records: 5 
#5: 
     io.netty.buffer.AdvancedLeakAwareByteBuf.release(AdvancedLeakAwareByteBuf.java:955) 
     com.example.network.listener.netty.PreprocessHandler.handle(PreprocessHandler.java:42) 
     com.example.network.listener.netty.UdpHandlerChain.handle(UdpHandlerChain.java:17) 
     com.example.network.listener.netty.UdpRequestExecutor$1.run(UdpRequestExecutor.java:89) 
     java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
     java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
     java.lang.Thread.run(Thread.java:745) 
#4: 
     io.netty.buffer.AdvancedLeakAwareByteBuf.readBytes(AdvancedLeakAwareByteBuf.java:495) 
     com.example.network.listener.netty.PreprocessHandler.handle(PreprocessHandler.java:39) 
     com.example.network.listener.netty.UdpHandlerChain.handle(UdpHandlerChain.java:17) 
     com.example.network.listener.netty.UdpRequestExecutor$1.run(UdpRequestExecutor.java:89) 
     java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
     java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
     java.lang.Thread.run(Thread.java:745) 
#3: 
     io.netty.buffer.AdvancedLeakAwareByteBuf.retain(AdvancedLeakAwareByteBuf.java:927) 
     io.netty.buffer.AdvancedLeakAwareByteBuf.retain(AdvancedLeakAwareByteBuf.java:35) 
     io.netty.util.ReferenceCountUtil.retain(ReferenceCountUtil.java:36) 
     io.netty.channel.DefaultAddressedEnvelope.retain(DefaultAddressedEnvelope.java:89) 
     io.netty.channel.socket.DatagramPacket.retain(DatagramPacket.java:67) 
     io.netty.channel.socket.DatagramPacket.retain(DatagramPacket.java:27) 
     io.netty.util.ReferenceCountUtil.retain(ReferenceCountUtil.java:36) 
     com.example.network.listener.netty.UdpRequestExecutor.channelRead(UdpRequestExecutor.java:71) 
     io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) 
     io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) 
     io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351) 
     io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334) 
     io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) 
     io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) 
     io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) 
     io.netty.channel.epoll.EpollDatagramChannel$EpollDatagramChannelUnsafe.epollInReady(EpollDatagramChannel.java:580) 
     io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:402) 
     io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:307) 
     io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873) 
     io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144) 
     java.lang.Thread.run(Thread.java:745) 
#2: 
     Hint: 'UdpRequestExecutor#0' will handle the message from this point. 
     io.netty.channel.DefaultAddressedEnvelope.touch(DefaultAddressedEnvelope.java:117) 
     io.netty.channel.socket.DatagramPacket.touch(DatagramPacket.java:85) 
     io.netty.channel.socket.DatagramPacket.touch(DatagramPacket.java:27) 
     io.netty.channel.DefaultChannelPipeline.touch(DefaultChannelPipeline.java:107) 
     io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:356) 
     io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351) 
     io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334) 
     io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) 
     io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) 
     io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) 
     io.netty.channel.epoll.EpollDatagramChannel$EpollDatagramChannelUnsafe.epollInReady(EpollDatagramChannel.java:580) 
     io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:402) 
     io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:307) 
     io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873) 
     io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144) 
     java.lang.Thread.run(Thread.java:745) 
#1: 
     Hint: 'DefaultChannelPipeline$HeadContext#0' will handle the message from this point. 
     io.netty.channel.DefaultAddressedEnvelope.touch(DefaultAddressedEnvelope.java:117) 
     io.netty.channel.socket.DatagramPacket.touch(DatagramPacket.java:85) 
     io.netty.channel.socket.DatagramPacket.touch(DatagramPacket.java:27) 
     io.netty.channel.DefaultChannelPipeline.touch(DefaultChannelPipeline.java:107) 
     io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:356) 
     io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) 
     io.netty.channel.epoll.EpollDatagramChannel$EpollDatagramChannelUnsafe.epollInReady(EpollDatagramChannel.java:580) 
     io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:402) 
     io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:307) 
     io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873) 
     io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144) 
     java.lang.Thread.run(Thread.java:745) 
Created at: 
     io.netty.buffer.PooledByteBufAllocator.newDirectBuffer(PooledByteBufAllocator.java:271) 
     io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:179) 
     io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:170) 
     io.netty.buffer.AbstractByteBufAllocator.ioBuffer(AbstractByteBufAllocator.java:131) 
     io.netty.channel.DefaultMaxMessagesRecvByteBufAllocator$MaxMessageHandle.allocate(DefaultMaxMessagesRecvByteBufAllocator.java:73) 
     io.netty.channel.RecvByteBufAllocator$DelegatingHandle.allocate(RecvByteBufAllocator.java:124) 
     io.netty.channel.epoll.EpollDatagramChannel$EpollDatagramChannelUnsafe.epollInReady(EpollDatagramChannel.java:544) 
     io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:402) 
     io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:307) 
     io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873) 
     io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144) 
     java.lang.Thread.run(Thread.java:745) 

上次访问是一个明确的release() ......

我使用了Netty 4.1.6.Final。

回答

1

异常消息指向Netty Wiki。从这些信息和痕迹看起来像在com.example.network.listener.netty.UdpRequestExecutor.channelRead(UdpRequestExecutor.java:71)是错误的。无论如何,在你的缓冲区引用的时候是> 0。你应该研究例子和责任矩阵来正确使用refcounts。

+0

请注意,此错误在我的日志中只出现一次......它怎么可能?服务器收到大量的请求.... –

+0

我不知道你配置泄漏检测的方式。默认情况下,它采样〜1%的缓冲区。无论如何,对于特定的buf(来自日志),很明显为什么它被认为是泄漏 - 过度使用'retain()' – IrLED

+0

这让我困惑......我在寻找一个缓冲区泄漏......所有缓冲区都被泄露。谢谢 –