What version of gRPC-Java are you using?
1.79.0
What is your environment?
- Operating System: Android (tested on Android 16)
- gRPC Transport: grpc-okhttp (via AndroidChannelBuilder)
- JDK: Android Runtime
- Dependencies:
- grpc-android: 1.79.0
- grpc-okhttp: 1.79.0
- grpc-protobuf: 1.79.0
- grpc-kotlin-stub: 1.5.0
What did you expect to see?
When the Android app is moved to the background, gRPC connections should gracefully handle the network state changes without crashing. The transport shutdown sequence should properly call transportShutdown() before transportTerminated().
What did you see instead?
The app consistently crashes approximately 5 seconds after being moved to the background:
FATAL EXCEPTION: OkHttpClientTransport
Process: com.notahotel.android.notahotel.dev, PID: 10823
java.lang.IllegalStateException: transportShutdown() must be called before transportTerminated().
at com.google.common.base.Preconditions.checkState(Preconditions.java:513)
at io.grpc.internal.InternalSubchannel$TransportListener.transportTerminated(InternalSubchannel.java:671)
at io.grpc.okhttp.OkHttpClientTransport$ClientFrameHandler.run(OkHttpClientTransport.java:1347)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1154)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:652)
at java.lang.Thread.run(Thread.java:1563)
Observations:
- The crash occurs on multiple OkHttpClientTransport threads simultaneously
- The timing is consistent: approximately 5 seconds after the app goes to background
- This issue does NOT occur with version 1.78.0 - only appears in 1.79.0
Steps to reproduce the bug
- Set up an Android app using AndroidChannelBuilder with grpc-java 1.79.0:
val channel = AndroidChannelBuilder
.forAddress(host, port)
.useTransportSecurity()
.context(applicationContext)
.build()
- Establish one or more active gRPC connections
- Move the app to the background (press home button or switch to another app)
- Wait approximately 5 seconds
- Observe the crash in logcat