ArrayIndexOutOfBoundsException With PooledByteBufAllocator Recycler implementaion
See original GitHub issueIssue Description
While trying to write an HttpMessage using HTTP1 with HttpClientCodec i.e HttpObjectEncoder, Netty is throwing an ArrayIndexOutOfBounds Exception while trying to allocate buffer for headers. Exception seems to be happening in the PooledByteBufAllocator Recycler Implementation.
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index -841651488 out of bounds for length 256
at io.netty.util.Recycler$Stack.pushNow(Recycler.java:666)
at io.netty.util.Recycler$Stack.push(Recycler.java:642)
at io.netty.util.Recycler$DefaultHandle.recycle(Recycler.java:236)
at io.netty.buffer.PoolThreadCache$MemoryRegionCache$Entry.recycle(PoolThreadCache.java:482)
at io.netty.buffer.PoolThreadCache$MemoryRegionCache.allocate(PoolThreadCache.java:412)
at io.netty.buffer.PoolThreadCache.allocate(PoolThreadCache.java:187)
at io.netty.buffer.PoolThreadCache.allocateSmall(PoolThreadCache.java:171)
at io.netty.buffer.PoolArena.allocate(PoolArena.java:189)
at io.netty.buffer.PoolArena.allocate(PoolArena.java:147)
at io.netty.buffer.PooledByteBufAllocator.newDirectBuffer(PooledByteBufAllocator.java:356)
at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:187)
at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:178)
at io.netty.buffer.AbstractByteBufAllocator.buffer(AbstractByteBufAllocator.java:115)
at io.netty.handler.codec.http.HttpObjectEncoder.encode(HttpObjectEncoder.java:93)
at io.netty.handler.codec.http.HttpClientCodec$Encoder.encode(HttpClientCodec.java:189)
at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:89) ... 111 more
A new buffer is being allocated in Encoder here - https://github.com/netty/netty/blob/ee3b9a5f7b1829e1095fdbbccb5490949ac3e94e/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java#L93.
Recycler code triggering the exception - https://github.com/netty/netty/blob/ee3b9a5f7b1829e1095fdbbccb5490949ac3e94e/common/src/main/java/io/netty/util/Recycler.java#L666
Similar issue seen with Recycler in the past - https://github.com/netty/netty/issues/9608
Netty version
4.1.51.Final
JVM version
Java 11
OS version
x86_64 GNU/Linux
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (10 by maintainers)
Top GitHub Comments
@atanu1991 today
@chrisvest I am facing similar issue while PooledByteBuAllocator while writing Http/2 request
Attaching the stack trace
java.lang.ArrayIndexOutOfBoundsException: Index 39 out of bounds for length 39 at io.netty.buffer.PoolArena.findSubpagePoolHead(PoolArena.java:267) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.PoolChunk.free(PoolChunk.java:453) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.PoolChunkList.free(PoolChunkList.java:120) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.PoolArena.freeChunk(PoolArena.java:258) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.PoolThreadCache$MemoryRegionCache.freeEntry(PoolThreadCache.java:430) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.PoolThreadCache$MemoryRegionCache.free(PoolThreadCache.java:396) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.PoolThreadCache$MemoryRegionCache.trim(PoolThreadCache.java:414) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.PoolThreadCache.trim(PoolThreadCache.java:277) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.PoolThreadCache.trim(PoolThreadCache.java:269) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.PoolThreadCache.trim(PoolThreadCache.java:258) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.PoolThreadCache.allocate(PoolThreadCache.java:170) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.PoolThreadCache.allocateSmall(PoolThreadCache.java:151) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.PoolArena.tcacheAllocateSmall(PoolArena.java:148) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.PoolArena.allocate(PoolArena.java:134) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.PoolArena.allocate(PoolArena.java:126) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.PooledByteBufAllocator.newDirectBuffer(PooledByteBufAllocator.java:395) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:188) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:179) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.buffer.AbstractByteBufAllocator.buffer(AbstractByteBufAllocator.java:116) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.handler.codec.http2.DefaultHttp2FrameWriter.writeHeadersInternal(DefaultHttp2FrameWriter.java:515) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.handler.codec.http2.DefaultHttp2FrameWriter.writeHeaders(DefaultHttp2FrameWriter.java:260) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder.sendHeaders(DefaultHttp2ConnectionEncoder.java:184) ~[netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder.writeHeaders0(DefaultHttp2ConnectionEncoder.java:233) [netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder.writeHeaders(DefaultHttp2ConnectionEncoder.java:151) [netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.handler.codec.http2.DecoratingHttp2FrameWriter.writeHeaders(DecoratingHttp2FrameWriter.java:45) [netty-all-4.1.68.Final.jar:4.1.68.Final] at com.rt.jio.scp.http2.client.active.standby.ScpHttp2EgressActiveStandbyClientRequestHandler.write(ScpHttp2EgressActiveStandbyClientRequestHandler.java:118) [rtSDP_Run.jar:?] at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717) [netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:709) [netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.channel.AbstractChannelHandlerContext$WriteTask.run(AbstractChannelHandlerContext.java:1069) [netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164) [netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469) [netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:384) [netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986) [netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [netty-all-4.1.68.Final.jar:4.1.68.Final] at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [netty-all-4.1.68.Final.jar:4.1.68.Final] at java.lang.Thread.run(Thread.java:832) [?:?]