Okhttp: java.lang.ArrayIndexOutOfBoundsException: size=8 offset=0 byteCount=579

Created on 18 Aug 2017  Â·  9Comments  Â·  Source: square/okhttp

Hello Square Team,
We've had a strange crash in spdy3.1 process,but we can not reproduce again, we don't know how to fix it, Could you help us please.

crash log:
java.lang.ArrayIndexOutOfBoundsException: size=8 offset=0 byteCount=579
at b.ae.d(SourceFile:30)
at okio.Okio$1.write(SourceFile:75)
at okio.AsyncTimeout$1.write(SourceFile:155)
at okio.RealBufferedSink.emitCompleteSegments(SourceFile:176)
at okio.RealBufferedSink.writeInt(SourceFile:140)
at okhttp3.internal.framed.Spdy3$Writer.goAway(SourceFile:462)
at okhttp3.internal.framed.FramedConnection.shutdown(SourceFile:435)
at okhttp3.internal.framed.FramedConnection.close(SourceFile:451)
at okhttp3.internal.framed.FramedConnection.access$900(SourceFile:55)
access$1100
access$1200
access$1300
access$1400
access$1500
access$2200
access$2302
access$2600
at okhttp3.internal.framed.FramedConnection$Reader.execute(SourceFile:609)
at okhttp3.internal.NamedRunnable.run(SourceFile:32)
at java.lang.Thread.run(Thread.java:818)

OKHttp version:3.2.0
OKio Version:1.6.0

bug

All 9 comments

Have you tried the latest version? That one is quite old.

On Thu, Aug 17, 2017 at 8:28 PM MichaelChansn notifications@github.com
wrote:

Hello Square Team,
We've had a strange crash in spdy3.1 process,but we can not reproduce
again, we don't know how to fix it, Could you help us please.

crash log:
java.lang.ArrayIndexOutOfBoundsException: size=8 offset=0 byteCount=579
at b.ae.d(SourceFile:30)
at okio.Okio$1.write(SourceFile:75)
at okio.AsyncTimeout$1.write(SourceFile:155)
at okio.RealBufferedSink.emitCompleteSegments(SourceFile:176)
at okio.RealBufferedSink.writeInt(SourceFile:140)
at okhttp3.internal.framed.Spdy3$Writer.goAway(SourceFile:462)
at okhttp3.internal.framed.FramedConnection.shutdown(SourceFile:435)
at okhttp3.internal.framed.FramedConnection.close(SourceFile:451)
at okhttp3.internal.framed.FramedConnection.access$900(SourceFile:55)
access$1100
access$1200
access$1300
access$1400
access$1500
access$2200
access$2302
access$2600
at okhttp3.internal.framed.FramedConnection$Reader.execute(SourceFile:609)
at okhttp3.internal.NamedRunnable.run(SourceFile:32)
at java.lang.Thread.run(Thread.java:818)

OKHttp version:3.2.0
OKio Version:1.6.0

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/square/okhttp/issues/3530, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEESzAAU3GK7jaPJFLVUmWCl7Nk79oks5sZQTPgaJpZM4O7DwA
.

Saw something similar in CI on a PR

https://s3.amazonaws.com/archive.travis-ci.org/jobs/268768635/log.txt?X-Amz-Expires=30&X-Amz-Date=20170827T060524Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJRYRXRSVGNKPKO5A/20170827/us-east-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=fdfd8d7e24bdc5dd10be5e18dff1fbae6eb329ebf9385452c1b83f7ec5a72251

Uncaught exception in OkHttp thread "OkHttp Dispatcher"
java.lang.ArrayIndexOutOfBoundsException: size=14 offset=0 byteCount=20
    at okio.Util.checkOffsetAndCount(Util.java:30)
    at okio.AsyncTimeout$1.write(AsyncTimeout.java:162)
    at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:171)
    at okio.RealBufferedSink.writeUtf8(RealBufferedSink.java:53)
    at okhttp3.internal.http1.Http1Codec.writeRequest(Http1Codec.java:173)
    at okhttp3.internal.http1.Http1Codec.writeRequestHeaders(Http1Codec.java:128)
    at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:52)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.internal.ws.WebSocketHttpTest$1.intercept(WebSocketHttpTest.java:68)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:202)
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:148)
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

Last test to start was: nullByteStringThrows(okhttp3.internal.ws.WebSocketHttpTest)

Typically ArrayIndexOutOfBoundsException in Okio indicates a thread-safety violation. If multiple threads are operating on the same Buffer at the same time, invariants are broken.

Unfortunately, segment pooling means that it is possible for a race condition in one area of the code to trigger a completely unrelated area of the code to fail. It’s pretty insidious.

Suppose we have three threads T1, T2, and T3, two buffers B1 and B2, and one segment S1.

T1 writes "foo" to B1, which creates S1.
T1 and T2 concurrently start a read 3 bytes from B1. They both read S1. This is a bug.
T1 reads the bytes, causing S1 to be put in the segment pool.
T3 writes "bar" to B2. which takes S1 from the segment pool.
Now T3 and T2 are both racing over S1, even though originally the race was between T1 and T2.

To avoid such races we need to avoid writing racy code! I think there’s probably something in our web sockets or their tests that is racy, which might be the case the failures above.

@swankjesse any chance it is the AsyncTimeout?

I don’t think it’s AsyncTimeout, since that doesn’t operate on any buffers.

Dear Team, I have used latest version of OkHttp but also facing the below issue? Can any one tell me the reason and how to handle it.?

06-19 12:54:44.038 6110 11426 E AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher 06-19 12:54:44.038 6110 11426 E AndroidRuntime: Process: com.geappliances.newfi20, PID: 6110 06-19 12:54:44.038 6110 11426 E AndroidRuntime: java.lang.ArrayIndexOutOfBoundsException: size=66 offset=0 byteCount=7676 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okio.Util.checkOffsetAndCount(Util.java:30) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okio.AsyncTimeout$1.write(AsyncTimeout.java:162) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:179) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okio.RealBufferedSink.writeUtf8(RealBufferedSink.java:54) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.http1.Http1Codec.writeRequest(Http1Codec.java:172) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.http1.Http1Codec.writeRequestHeaders(Http1Codec.java:130) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:50) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:144) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 06-19 12:54:44.038 6110 11426 E AndroidRuntime: at java.lang.Thread.run(Thread.java:764)

This usually indicates unsafe concurrent access to a Buffer or other Okio stream.

Yes, I have used multiple thread in JobIntentService class of android.

Was this page helpful?
0 / 5 - 0 ratings