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.