libp2p / jvm-libp2p

a libp2p implementation for the JVM, written in Kotlin 🔥
https://libp2p.io
Apache License 2.0
275 stars 77 forks source link

Yamux memory leak #291

Closed ianopolous closed 1 year ago

ianopolous commented 1 year ago

I'm seeing this in Nabu in a bitswap unit test:

May 31, 2023 8:02:11 PM io.netty.util.ResourceLeakDetector reportTracedLeak SEVERE: LEAK: ByteBuf.release() was not called before it's garbage-collected. See https://netty.io/wiki/reference-counted-objects.html for more information. Recent access records: Created at: io.netty.buffer.PooledByteBufAllocator.newDirectBuffer(PooledByteBufAllocator.java:403) io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:188) io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:179) io.netty.buffer.AbstractByteBufAllocator.ioBuffer(AbstractByteBufAllocator.java:132) io.netty.handler.codec.MessageToByteEncoder.allocateBuffer(MessageToByteEncoder.java:140) io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:105) io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:881) io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:863) io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:968) io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:856) io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:113) io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:881) io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:863) io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:968) io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:856) io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:113) io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:879) io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:863) io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:968) io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:856) io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:851) io.libp2p.multistream.Negotiator$GenericHandler.channelActive(Negotiator.kt:90) io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:262) io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:238) io.netty.channel.AbstractChannelHandlerContext.fireChannelActive(AbstractChannelHandlerContext.java:231) io.netty.channel.DefaultChannelPipeline$HeadContext.channelActive(DefaultChannelPipeline.java:1398) io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:258) io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:238) io.netty.channel.DefaultChannelPipeline.fireChannelActive(DefaultChannelPipeline.java:895) io.netty.channel.AbstractChannel$AbstractUnsafe.register0(AbstractChannel.java:522) io.netty.channel.AbstractChannel$AbstractUnsafe.register(AbstractChannel.java:480) io.netty.channel.SingleThreadEventLoop.register(SingleThreadEventLoop.java:89) io.netty.channel.SingleThreadEventLoop.register(SingleThreadEventLoop.java:83) io.libp2p.etc.util.netty.mux.AbstractMuxHandler.createChild(AbstractMuxHandler.kt:135) io.libp2p.etc.util.netty.mux.AbstractMuxHandler.onRemoteOpen(AbstractMuxHandler.kt:90) io.libp2p.mux.yamux.YamuxHandler.handleFlags(YamuxHandler.kt:78) io.libp2p.mux.yamux.YamuxHandler.handleWindowUpdate(YamuxHandler.kt:108) io.libp2p.mux.yamux.YamuxHandler.channelRead(YamuxHandler.kt:59) io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318) io.netty.handler.codec.ByteToMessageCodec.channelRead(ByteToMessageCodec.java:103) io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436) io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:333) io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:454) io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) java.base/java.lang.Thread.run(Thread.java:833)

Nashatyrev commented 1 year ago

Fixed by #292