Description
This should document how to handle network connectivity changes on Android. This will only apply to OkHttp users, as Cronet internally manages and responds to connectivity state changes outside of the gRPC stack.
This document should include any current limitations and be updated when the respective fixes/enhancements are checked in, such as:
-
When the network goes down and an RPC is attempted, the gRPC channel will enter a DNS resolution backoff state running on a fixed 60 second timer. When the connection comes back online, it may take up to 60 seconds before the channel successfully reconnects. core: add resetConnectBackoff() method to ManagedChannel #3580 adds a
resetConnectBackoff()
method onManagedChannel
that short-circuits this backoff. Android apps using gRPC OkHttp should monitor the network state and trigger this method when the device moves from offline to online. Further, Use exponential backoff in DNS resolver #3685 tracks using exponential backoff in the DNS resolver which will help mitigate this issue even withoutresetConnectBackoff()
when the network is down only briefly. -
Supporting smooth network transitions: When the Android device moves from cell only to cell+wifi, the OS will issue a network notification indicating the the cell connection will be terminate soon (typically ~30 seconds). Currently new RPCs issued on a gRPC channel during this time will continue to use an established cell connection, meaning they will fail if still running when the OS terminates the cell network. Support smooth network changes #3688 tracks adding a notification method on the
ManagedChannel
to allow apps to continue any on-going RPCs on the cellular connection but force new RPCs to use wifi, reducing the disruption caused by the switch from cell to wifi. This functionality is in-review in core: add shutdownTransports() method to ManagedChannel #3904.