In rare occasion Netty throw this kind of exception:
java.lang.IndexOutOfBoundsException: readerIndex(37) + length(2) exceeds writerIndex(185): UnpooledHeapByteBuf(ridx: 37, widx: 185, cap: 185/185) at io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1405) at io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1392) at io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:872) at io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:880)
The code is :
private void checkReadableBytes0(int minimumReadableBytes) {
ensureAccessible();
if (readerIndex > writerIndex - minimumReadableBytes) {
throw new IndexOutOfBoundsException(String.format(
"readerIndex(%d) + length(%d) exceeds writerIndex(%d): %s",
readerIndex, minimumReadableBytes, writerIndex, this));
}
}
(37 > 185 - 2) should be true, how can it raise an exception ??
This looks strange. Are you sure you not share the same ByteBuf
with different threads ? If this is not the case please open an issue with more informations or even better a reproducer in the Netty issue tracker:
For me helped answer from maximdim : Spring WebFlux, Security and request body
Main idea then you need to use DataBufferUtils.join(exchange.getRequest().getBody())
, because first, you need to collect the all request body (join).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.