[英]Netty UnpooledHeapByteBuf, strange and unjustified IndexOutOfBoundsException
在极少数情况下,Netty 会抛出这种异常:
java.lang.IndexOutOfBoundsException: readerIndex(37) + length(2) 超过 writerIndex(185): UnpooledHeapByteBuf(ridx: 37, widx: 185, cap: 185/185) at io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractBuf.) java:1405) 在 io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1392) 在 io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:872) 在 io.netty.buffer.AbstractByteBuftract.readBytes(AbstractByteBuftract.readBytes(AbstractByteBuf.java:1392) .java:880)
代码是:
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) 应该是真的,怎么会引发异常??
这看起来很奇怪。 您确定不与其他线程共享同一ByteBuf
吗? 如果不是这种情况,请在Netty问题跟踪器中打开一个包含更多信息的问题,甚至更好的复制者:
对我来说,来自maximdim 的帮助回答: Spring WebFlux、安全性和请求正文
主要思想然后您需要使用DataBufferUtils.join(exchange.getRequest().getBody())
,因为首先,您需要收集所有请求正文(加入)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.