首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Netty UnpooledHeapByteBuf,奇怪和不合理的IndexOutOfBoundsException

Netty UnpooledHeapByteBuf,奇怪和不合理的IndexOutOfBoundsException
EN

Stack Overflow用户
提问于 2018-06-05 20:31:33
回答 2查看 506关注 0票数 0

在极少数情况下,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)

代码是:

代码语言:javascript
复制
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)应该是真的,它怎么会引发异常?

EN

回答 2

Stack Overflow用户

发布于 2018-06-10 07:15:44

这看起来很奇怪。您确定您没有在不同线程之间共享相同的ByteBuf吗?如果不是这样,请在Netty问题跟踪器中打开一个包含更多信息的问题,或者更好的复制器:

https://github.com/netty/netty

票数 0
EN

Stack Overflow用户

发布于 2021-11-23 15:33:35

对我来说,来自maximdim的帮助回答:Spring WebFlux, Security and request body

主要思想是你需要使用DataBufferUtils.join(exchange.getRequest().getBody()),因为首先,你需要收集所有的请求体(join)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50700159

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档