question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ArrayIndexOutOfBoundsException With PooledByteBufAllocator Recycler implementaion

See original GitHub issue

Issue 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:closed
  • Created 3 years ago
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
normanmaurercommented, Dec 9, 2021

@atanu1991 today

1reaction
EzajAnsaricommented, Nov 28, 2021

@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) [?:?]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Recycler View Fatal Exception: java.lang ... - Stack Overflow
I would start by looking at the adapters that have implemented OnClickListener in any of its ViewHolders. Check how you retrieve the adapter ......
Read more >
Netty 4.1.73.Final released - Netty.news
This release fixes a bug which can cause an ArrayIndexOutOfBoundsException when using the PooledByteBufAllocator.
Read more >
IndexOutOfBoundsException in RecyclerView ... - Issue Tracker
This bug was observed on 2 of our users so far using Nexus4 (Android 4.4.4/Rooted) and Samsung I9060(Android 4.2.2) - stack trace:
Read more >
Recyclerview - Android Developers
Display large sets of data in your UI while minimizing memory usage. This table lists all the artifacts in the androidx.recyclerview group. Artifact,...
Read more >
recyclerview/recyclerview/src/main/java/androidx ... - Google Git
prevent recycling or ItemAnimator not implementing the contract properly. ({@link. * > Adapter#onFailedToRecycleView(ViewHolder)}).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found