On iOS devices, network transitions happen frequently. A device may have multiple interfaces to connect to network, and these interfaces may become broken or alive at any time. This document describes how these network changes should be handled by gRPC and current issues related.
We classify network connectivity in three categories: WiFi, cellular, and none. Currently, the network connectivity information is obtained from SCNetworkReachability
API and the category is determined by SCNetworkReachabilityFlags
as follows:
Reachable | ConnectionRequired | IsWAAN | Category |
---|---|---|---|
0 | X | X | None |
X | 1 | X | None |
1 | 0 | 0 | WiFi |
1 | 0 | 1 | Cellular |
Whenever there is a switch of network connectivity between these three categories, the previous channels is assumed to be broken. If there is an unfinished call, the call should return with status code UNAVAILABLE
. All active gRPC channels will be destroyed so that any new call will trigger creation of new channel over new interface. In addition to that, when a TCP connection breaks, the corresponding channel should also be destroyed and calls be canceled with status code UNAVAILABLE
.
gRPC currently uses BSD sockets for TCP connections. There are several issues related to BSD sockets known to us that causes problems. gRPC has a plan to switch to CFStream API for TCP connections which resolves some of these problems.
Other known issue(s):