Seems like you not correctly retain the ByteBuf before hand it over to your 
method and so it is already released. You need to ensure you call 
buffer.retain() before hand it over (as it seems your method runs in another 
thread as the ChannelHandler itself) and then buffer.release() after you are 
done with it.

Bye
Norman



> On 19. Mar 2018, at 18:46, [email protected] wrote:
> 
> Hi. I am receiving data over a netty channel and than after striping 4 bytes 
> I am writing it to another netty channel.  Following function is trying to 
> achieve this.
> 
> @Override
> public void orderedPacket(ByteBuf packet) { 
>  //   log.info(packet.toString());
>     byte[] bytes = new byte[packet.capacity() - 4 ];
>     packet.getBytes(4, bytes);
>     ChannelFuture cf = hostChannel.writeAndFlush(bytes);
> 
>   //  if (!cf.isSuccess()) log.error("write back to host not successful {}", 
> cf.cause());
> 
> }
> 
> However it throws following exception. 
> 
> 
> 11:28:21.091 [nioEventLoopGroup-4-4] WARN  i.n.channel.DefaultChannelPipeline 
> - An exceptionCaught() event was fired, and it reached at the tail of the 
> pipeline. It usually means the last handler in the pipeline did not handle 
> the exception.
> io.netty.util.IllegalReferenceCountException: refCnt: 0
>         at 
> io.netty.buffer.AbstractByteBuf.ensureAccessible(AbstractByteBuf.java:1415) 
> ~[sosagent.jar:1.0-SNAPSHOT]
>         at 
> io.netty.buffer.AbstractByteBuf.checkIndex(AbstractByteBuf.java:1354) 
> ~[sosagent.jar:1.0-SNAPSHOT]
>         at 
> io.netty.buffer.UnsafeByteBufUtil.getBytes(UnsafeByteBufUtil.java:481) 
> ~[sosagent.jar:1.0-SNAPSHOT]
>         at 
> io.netty.buffer.PooledUnsafeDirectByteBuf.getBytes(PooledUnsafeDirectByteBuf.java:131)
>  ~[sosagent.jar:1.0-SNAPSHOT]
>         at 
> io.netty.buffer.PooledSlicedByteBuf.getBytes(PooledSlicedByteBuf.java:233) 
> ~[sosagent.jar:1.0-SNAPSHOT]
>         at io.netty.buffer.AbstractByteBuf.getBytes(AbstractByteBuf.java:474) 
> ~[sosagent.jar:1.0-SNAPSHOT]
>         at 
> edu.clemson.openflow.sos.agent.AgentClient.orderedPacket(AgentClient.java:81) 
> ~[sosagent.jar:1.0-SNAPSHOT]
>         at 
> edu.clemson.openflow.sos.buf.OrderedPacketInitiator.orderedPacket(OrderedPacketInitiator.java:17)
>  ~[sosagent.jar:1.0-SNAPSHOT]
>         at edu.clemson.openflow.sos.buf.Buffer.sendData(Buffer.java:84) 
> ~[sosagent.jar:1.0-SNAPSHOT]
> 
> 
> 
> The bold line in stack-trace corresponds to  packet.getBytes(4, bytes); in my 
> method.
> 
> Any idea what might be problem here.
> 
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Netty discussions" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/netty/e46725a9-eea6-45b5-99bc-140a3b907a11%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/netty/e46725a9-eea6-45b5-99bc-140a3b907a11%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/netty/535E10D1-1ACC-4230-9544-B6F71683C63C%40googlemail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to