在极少数情况下,Netty会抛出这样的异常:
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)的
java.lang.IndexOutOfBoundsException: readerIndex(37) + length(2)超过writerIndex(185):UnpooledHeapByteBuf(ridx: 37,widx: 185,cap: 185/185)
代码是:
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)应该是真的,它怎么会引发异常?
发布于 2018-06-10 07:15:44
这看起来很奇怪。您确定您没有在不同线程之间共享相同的ByteBuf
吗?如果不是这样,请在Netty问题跟踪器中打开一个包含更多信息的问题,或者更好的复制器:
发布于 2021-11-23 15:33:35
对我来说,来自maximdim的帮助回答:Spring WebFlux, Security and request body
主要思想是你需要使用DataBufferUtils.join(exchange.getRequest().getBody())
,因为首先,你需要收集所有的请求体(join)。
https://stackoverflow.com/questions/50700159
复制相似问题