Okhttp: ArrayIndexOutOfBoundsException: length=8192; index=8192 when using Http2

Created on 24 Sep 2020  路  6Comments  路  Source: square/okhttp

We recently upgraded okhttp to 3.12.12 and opened http2. An exception occurred on the line.

java.lang.ArrayIndexOutOfBoundsException: length=8192; index=8192 okio.Buffer.okio.Buffer writeByte(int)(RQDSRC:1152) okio.RealBufferedSink.okio.BufferedSink writeByte(int)(RQDSRC:124) okhttp3.internal.http2.Http2Writer.void writeMedium(okio.BufferedSink,int)(RQDSRC:283) okhttp3.internal.http2.Http2Writer.void frameHeader(int,int,byte,byte)(RQDSRC:271) okhttp3.internal.http2.Http2Writer.void goAway(int,okhttp3.internal.http2.ErrorCode,byte[])(RQDSRC:238) okhttp3.internal.http2.Http2Connection.void shutdown(okhttp3.internal.http2.ErrorCode)(RQDSRC:464) okhttp3.internal.http2.Http2Connection.void close(okhttp3.internal.http2.ErrorCode,okhttp3.internal.http2.ErrorCode)(RQDSRC:480) okhttp3.internal.http2.Http2Connection$ReaderRunnable.void execute()(RQDSRC:687) okhttp3.internal.NamedRunnable.void run()(RQDSRC:32) java.lang.Thread.run(Thread.java:764)

bug needs info

All 6 comments

Yikes. Might be fixed by grabbing the latest Okio.
"com.squareup.okio:okio:2.8.0"

Not enough information to take action on this otherwise.

@mabeijianxi any chance of a server and exact details of the mobile device we can reproduce against, otherwise it's unlikely we can reproduce. Please reopen with enough information to reproduce.

@yschimke @swankjesse The phones in question are all vivo, and the system version is 7.1.2, 8.0.0, 8.1.0, 9.0
image

@swankjesse Found a new error.
vivo X21A;Android 9,level 28

java.lang.ArrayIndexOutOfBoundsException: length=8192; index=8192 okio.Buffer.okio.Buffer writeByte(int)(RQDSRC:1152) okhttp3.internal.platform.Platform.byte[] concatLengthPrefixed(java.util.List)(RQDSRC:264) okhttp3.internal.platform.AndroidPlatform.void configureTlsExtensions(javax.net.ssl.SSLSocket,java.lang.String,java.util.List)(RQDSRC:128) okhttp3.internal.connection.RealConnection.void connectTls(okhttp3.internal.connection.ConnectionSpecSelector)(RQDSRC:315) okhttp3.internal.connection.RealConnection.void establishProtocol(okhttp3.internal.connection.ConnectionSpecSelector,int,okhttp3.Call,okhttp3.EventListener)(RQDSRC:284) okhttp3.internal.connection.RealConnection.void connect(int,int,int,int,boolean,okhttp3.Call,okhttp3.EventListener)(RQDSRC:169) okhttp3.internal.connection.StreamAllocation.okhttp3.internal.connection.RealConnection findConnection(int,int,int,int,boolean)(RQDSRC:258) okhttp3.internal.connection.StreamAllocation.okhttp3.internal.connection.RealConnection findHealthyConnection(int,int,int,int,boolean,boolean)(RQDSRC:135) okhttp3.internal.connection.StreamAllocation.okhttp3.internal.http.HttpCodec newStream(okhttp3.OkHttpClient,okhttp3.Interceptor$Chain,boolean)(RQDSRC:114) okhttp3.internal.connection.ConnectInterceptor.okhttp3.Response intercept(okhttp3.Interceptor$Chain)(RQDSRC:42) okhttp3.internal.http.RealInterceptorChain.okhttp3.Response proceed(okhttp3.Request,okhttp3.internal.connection.StreamAllocation,okhttp3.internal.http.HttpCodec,okhttp3.internal.connection.RealConnection)(RQDSRC:147) okhttp3.internal.http.RealInterceptorChain.okhttp3.Response proceed(okhttp3.Request)(RQDSRC:121) okhttp3.internal.cache.CacheInterceptor.okhttp3.Response intercept(okhttp3.Interceptor$Chain)(RQDSRC:93) okhttp3.internal.http.RealInterceptorChain.okhttp3.Response proceed(okhttp3.Request,okhttp3.internal.connection.StreamAllocation,okhttp3.internal.http.HttpCodec,okhttp3.internal.connection.RealConnection)(RQDSRC:147) okhttp3.internal.http.RealInterceptorChain.okhttp3.Response proceed(okhttp3.Request)(RQDSRC:121) okhttp3.internal.http.BridgeInterceptor.okhttp3.Response intercept(okhttp3.Interceptor$Chain)(RQDSRC:93) okhttp3.internal.http.RealInterceptorChain.okhttp3.Response proceed(okhttp3.Request,okhttp3.internal.connection.StreamAllocation,okhttp3.internal.http.HttpCodec,okhttp3.internal.connection.RealConnection)(RQDSRC:147) okhttp3.internal.http.RetryAndFollowUpInterceptor.okhttp3.Response intercept(okhttp3.Interceptor$Chain)(RQDSRC:127) okhttp3.internal.http.RealInterceptorChain.okhttp3.Response proceed(okhttp3.Request,okhttp3.internal.connection.StreamAllocation,okhttp3.internal.http.HttpCodec,okhttp3.internal.connection.RealConnection)(RQDSRC:147) okhttp3.internal.http.RealInterceptorChain.okhttp3.Response proceed(okhttp3.Request)(RQDSRC:121) okhttp3.RealCall.okhttp3.Response getResponseWithInterceptorChain()(RQDSRC:257) okhttp3.RealCall$AsyncCall.void execute()(RQDSRC:201) okhttp3.internal.NamedRunnable.void run()(RQDSRC:32) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) java.lang.Thread.run(Thread.java:764)

@swankjesse
I also encountered the same problem, can you tell us the cause of the problem and the progress of the repair?
java.lang.ArrayIndexOutOfBoundsException: length=8192; index=8192
at com.android.okhttp.okio.Buffer.writeByte(Buffer.java:973)
at com.android.okhttp.okio.RealBufferedSink.writeByte(RealBufferedSink.java:121)
at com.android.okhttp.internal.framed.Http2.writeMedium(Http2.java:767)
at com.android.okhttp.internal.framed.Http2.access$600(Http2.java:42)
at com.android.okhttp.internal.framed.Http2$Writer.frameHeader(Http2.java:572)
at com.android.okhttp.internal.framed.Http2$Writer.goAway(Http2.java:537)
at com.android.okhttp.internal.framed.FramedConnection.shutdown(FramedConnection.java:440)
at com.android.okhttp.internal.framed.FramedConnection.close(FramedConnection.java:457)
at com.android.okhttp.internal.framed.FramedConnection.access$1200(FramedConnection.java:55)
at com.android.okhttp.internal.framed.FramedConnection$Reader.execute(FramedConnection.java:615)
at com.android.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
at java.lang.Thread.run(Thread.java:764)

If your see com.android.okhttp in the stack trace you're using a very old OkHttp that's bundled with Android. Try using OkHttp directly which has lots of bugs fixed.

Was this page helpful?
0 / 5 - 0 ratings