IllegalReferenceCountException - "Failed to release a message: PooledSlicedByteBuf(freed)"
See original GitHub issueWhen I execute the following code, I get the error message mentioned in the title (and below).
It only happens when not registering an error handler for a flux that actually throws an exception.
Anyway, this might cause severe problems (memory leak?), so I thought I would mention it.
Expected Behavior
No IllegalReferenceCountException
Actual Behavior
Exception and error log.
02-06-2020 19:07:25.228 [reactor-tcp-nio-2] WARN i.n.u.ReferenceCountUtil - Failed to release a message: PooledSlicedByteBuf(freed)
io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1
at io.netty.util.internal.ReferenceCountUpdater.toLiveRealRefCnt(ReferenceCountUpdater.java:74)
at io.netty.util.internal.ReferenceCountUpdater.release(ReferenceCountUpdater.java:138)
at io.netty.buffer.AbstractReferenceCountedByteBuf.release(AbstractReferenceCountedByteBuf.java:100)
at io.netty.util.ReferenceCountUtil.release(ReferenceCountUtil.java:88)
at io.netty.util.ReferenceCountUtil.safeRelease(ReferenceCountUtil.java:113)
at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:109)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:321)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:295)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:832)
Steps to Reproduce
Sorry for this not being a real unit test, but you will get the idea.
@Test
public void asdf() throws Exception {
CloseableChannel server = RSocketServer.create((setup, sendingRSocket) -> Mono.just(new RSocket() {
@Override
public Flux<Payload> requestStream(Payload payload) {
if (payload.getDataUtf8().equals("flux")) {
return Flux.interval(Duration.ofMillis(1))
.doOnNext(aLong -> System.out.println("Server-side doOnNext: " + aLong))
.doOnCancel(() -> System.out.println("Server-side doOnCancel"))
.map(aLong -> DefaultPayload.create("" + aLong));
} else {
return Flux.error(new RuntimeException("Some Exception for this test"));
}
}
}))
.bind(TcpServerTransport.create(TcpServer.create().host("localhost").port(7890)))
.block();
RSocket client = RSocketConnector.create()
.connect(TcpClientTransport.create(TcpClient.create().host("localhost").port(7890)))
.block();
client.requestStream(DefaultPayload.create("exception"))
.take(10)
.subscribe(payload -> System.out.println(payload.getDataUtf8())); // Note: no error handler!
Thread.sleep(1000);
}
Possible Solution
Your Environment
- RSocket version(s) used: 1.0.0
- Other relevant libraries versions (eg.
netty
, …): default rsocket dependencies - Platform (eg. JVM version (
javar -version
) or Node version (node --version
)): openjdk 14.0.1 2020-04-14 OpenJDK Runtime Environment AdoptOpenJDK (build 14.0.1+7) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 14.0.1+7, mixed mode, sharing) - OS and version (eg
uname -a
): MacOS
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Netty neophyte question on WARNING: Failed to release a ...
java - Netty neophyte question on WARNING: Failed to release a message: PooledUnsafeDirectByteBuf(freed) - Stack Overflow. Stack Overflow for ...
Read more >reactor/reactor-netty - Gitter
ReferenceCountUtil : Failed to release a message: DefaultHttpContent(data: PooledSlicedByteBuf(freed), decoderResult: success). io.netty.util.
Read more >[#CAMEL-10409] Double release of netty buffer - ASF JIRA
ReferenceCountUtil : Failed to release a message: AdvancedLeakAwareByteBuf(PooledUnsafeDirectByteBuf(freed)) io.netty.util.
Read more >io.netty.IllegalReferenceCountException: refCnt: 0 exception.
It usually means the last handler in the pipeline did not handle the ... before hand it over to your method and so...
Read more >ReferenceCountUtil.java example - Javatips.net
isWarnEnabled()) { logger.warn("Failed to release a message: ... Schedules the specified object to be released when the caller thread terminates.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A fix for #858 will be provided but we are not sure how the
ByteBuf
double release may be related to the error-handler issue since the unite test provided is not reproducing it.Therefore, once #858 is fixed, please double check this one and if it is not reproducing anyhow or reproduces with another test, please provide extra input if you want us to continue working on this.
Cheers, Oleh
Closed because of lack of information