Seeing the following crashes on Android with Okhttp v4.3.0, not happening on v4.2.2
Fatal Exception: m0.a
at okio.Buffer.writableSegment$okio(Buffer.java:1812)
at okio.Buffer.writeByte(Buffer.java:1662)
at okio.RealBufferedSink.writeByte(RealBufferedSink.java:197)
at okhttp3.internal.Util.writeMedium(Util.java:309)
at okhttp3.internal.http2.Http2Writer.frameHeader(Http2Writer.java:261)
at okhttp3.internal.http2.Http2Writer.settings(Http2Writer.java:173)
at okhttp3.internal.http2.Http2Connection.start(Http2Connection.java:496)
at okhttp3.internal.http2.Http2Connection.start$default(Http2Connection.java:493)
at okhttp3.internal.connection.RealConnection.startHttp2(RealConnection.java:329)
at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:312)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:182)
at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:238)
at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:111)
at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.java:79)
at okhttp3.internal.connection.Transmitter.newExchange$okhttp(Transmitter.java:163)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:35)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:112)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:87)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:82)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:112)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:87)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:84)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:112)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:71)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:112)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:87)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:194)
at okhttp3.RealCall$AsyncCall.run(RealCall.java:138)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
and
Fatal Exception: m0.a
at okio.Segment.pop(Segment.java:89)
at okio.Buffer.skip(Buffer.java:1478)
at okio.RealBufferedSource.skip(RealBufferedSource.java:431)
at okhttp3.internal.http2.Http2Connection$ReaderRunnable.data(Http2Connection.java:643)
at okhttp3.internal.http2.Http2Reader.readData(Http2Reader.java:178)
at okhttp3.internal.http2.Http2Reader.nextFrame(Http2Reader.java:117)
at okhttp3.internal.http2.Http2Connection$ReaderRunnable.run(Http2Connection.java:614)
at java.lang.Thread.run(Thread.java:919)
I鈥檓 running a pretty extensive stress test to try to shake out this regression, but I鈥檝e been unsuccessful at reproducing thus far.
Typically these kinds of crashes indicate thread-unsafe operations on Okio buffers. Unfortunately the crashes can sometimes occur far away from the bad unsafe code, because the unsafe code corrupts Okio鈥檚 segment pool.
I鈥檇 like to create a special build of Okio to help root out these bugs. When that鈥檚 ready I hope you鈥檒l be able to run it.
@swankjesse thanks, I'll will test as soon as you have something ready.
Are you using AGP 4.0.0 with R8? I've had similar exceptions with that combination.
I've opened an issue on the R8 issue tracker, which also includes a project where you can reproduce the issue: https://issuetracker.google.com/issues/147411673
Wow, great find @Stonos!
@Stonos Yes, AGP 4.0.0-alpha07 with R8, thanks for logging it.
Update from the R8 issue tracker: They're working on a fix. For now, adding the following keep rule seems to resolve the issue:
-keep class okio.SegmentPool { *; }
Make you sure you put a big # TODO Remove once R8 fixes <issue link> so that rule doesn't stay in your rules forever!
Fixed in R8 on Jan 16. I suspect this probably made it into 4.0.0-alpha09. Update your Android Gradle Plugin and you should be good.