Skip to content

java.lang.IllegalStateException: too early; can't read the trailers yet #3049

@YuriiKot

Description

@YuriiKot

Hello!

We have an Android app with huge amount of users and getting crash in Android app

java.lang.IllegalStateException: too early; can't read the trailers yet
        at okhttp3.internal.http2.Http2Stream.trailers(Http2Stream:163)
        at okhttp3.internal.http2.Http2ExchangeCodec.trailers(Http2ExchangeCodec:118)
        at okhttp3.internal.connection.Exchange.trailers(Exchange:140)
        at okhttp3.Response.trailers(Response:180)
        at com.squareup.wire.internal.GrpcKt.grpcResponseToException(GrpcKt:195)
        at com.squareup.wire.internal.GrpcKt$readFromResponseBodyCallback$1$onResponse$1.invokeSuspend(GrpcKt:109)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask:108)
        at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoopImplBase:280)
        at kotlinx.coroutines.BlockingCoroutine.joinBlocking(BlockingCoroutine:85)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(BuildersKt__BuildersKt:59)
        at kotlinx.coroutines.BuildersKt.runBlocking(BuildersKt:1)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(BuildersKt__BuildersKt:38)
        at kotlinx.coroutines.BuildersKt.runBlocking$default(BuildersKt:1)
        at com.squareup.wire.internal.GrpcKt$readFromResponseBodyCallback$1.onResponse(GrpcKt:98)
        at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall:519)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
        at java.lang.Thread.run(Thread.java:1012)

Related thread trace

Thread 2919 - OkHttp https://api.xxx.com/... - (WAITING)
        at java.lang.Object.wait(Object.java:-2)
        at java.lang.Object.wait(Object.java:386)
        at java.lang.Object.wait(Object.java:524)
        at okhttp3.internal.http2.Http2Stream.waitForIo$okhttp(Http2Stream:714)
        at okhttp3.internal.http2.Http2Stream$FramingSource.read(Http2Stream:376)
        at okhttp3.internal.connection.Exchange$ResponseBodySource.read(Exchange:281)
        at okio.RealBufferedSource.exhausted(RealBufferedSource:200)
        at com.squareup.wire.internal.GrpcMessageSource.read(GrpcMessageSource:37)
        at com.squareup.wire.internal.GrpcKt$readFromResponseBodyCallback$1$onResponse$1.invokeSuspend(GrpcKt:104)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask:108)
        at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoopImplBase:280)
        at kotlinx.coroutines.BlockingCoroutine.joinBlocking(BlockingCoroutine:85)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(BuildersKt__BuildersKt:59)
        at kotlinx.coroutines.BuildersKt.runBlocking(BuildersKt:1)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(BuildersKt__BuildersKt:38)
        at kotlinx.coroutines.BuildersKt.runBlocking$default(BuildersKt:1)
        at com.squareup.wire.internal.GrpcKt$readFromResponseBodyCallback$1.onResponse(GrpcKt:98)
        at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall:519)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
        at java.lang.Thread.run(Thread.java:1012)

Most of the time happens in background after activity stop or resume and trying to establish connection

Steps to reproduce:

  1. Start bidi
  2. Throw IOException here
  3. Throw IllegalStateException here

It's rare edge case for prod that you need to have those 2 exceptions, but still around 0.002%

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions