Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ClientNetworkMonitor for tracking network changes #387

Merged
merged 7 commits into from
Mar 1, 2019

Conversation

rebello95
Copy link
Collaborator

@rebello95 rebello95 commented Mar 1, 2019

The SwiftGRPC implementation that is backed by [gRPC-Core(https://github.com/grpc/grpc) (and not SwiftNIO) is known to have some connectivity issues on iOS clients - namely, silently disconnecting (making it seem like active calls/connections are hanging) when switching between wifi <> cellular. The root cause of these problems is that the backing gRPC-Core doesn't get the optimizations made by iOS' networking stack when these types of changes occur, and isn't able to handle them itself.

There is also documentation of this behavior in this gRPC-Core readme.

To aid in this problem, we're adding a ClientNetworkMonitor that monitors the device for events that can cause gRPC to disconnect silently. We recommend utilizing this component to call shutdown() (or destroy) any active Channel instances, and start new ones when the network is reachable.

Details:

  • Switching between wifi <> cellular: Channels silently disconnect
  • Switching between 3G <> LTE (etc.): Channels silently disconnect
  • Network becoming unreachable: Most times channels will time out after a few seconds, but ClientNetworkMonitor will notify of these changes much faster
  • Switching between background <> foreground: No known issues

Original issue: #337.

The SwiftGRPC implementation that is backed by [gRPC-Core](https://github.com/grpc/grpc)
(and not SwiftNIO) is known to have some connectivity issues on iOS clients - namely, silently
disconnecting (making it seem like active calls/connections are hanging) when switching
between wifi <> cellular. The root cause of these problems is that the
backing gRPC-Core doesn't get the optimizations made by iOS' networking stack when these
types of changes occur, and isn't able to handle them itself.

To aid in this problem, we're adding a [`ClientNetworkMonitor`](./Sources/SwiftGRPC/Core/ClientNetworkMonitor.swift)
that monitors the device for events that can cause gRPC to disconnect silently. We recommend utilizing this component to call `shutdown()` (or destroy) any active `Channel` instances, and start new ones when the network is reachable.

Details:
- **Switching between wifi <> cellular:** Channels silently disconnect
- **Network becoming unreachable:** Most times channels will time out after a few seconds, but
  `ClientNetworkMonitor` will notify of these changes much faster
- **Switching between background <> foreground:** No known issues

Original issue: grpc#337.
@rebello95 rebello95 force-pushed the client-connectivity branch from eb5a84f to e118576 Compare March 1, 2019 05:18
Sources/SwiftGRPC/Core/ClientNetworkMonitor.swift Outdated Show resolved Hide resolved
Sources/SwiftGRPC/Core/ClientNetworkMonitor.swift Outdated Show resolved Hide resolved
Sources/SwiftGRPC/Core/ClientNetworkMonitor.swift Outdated Show resolved Hide resolved
Sources/SwiftGRPC/Core/ClientNetworkMonitor.swift Outdated Show resolved Hide resolved
Sources/SwiftGRPC/Core/ClientNetworkMonitor.swift Outdated Show resolved Hide resolved
Sources/SwiftGRPC/Core/ClientNetworkMonitor.swift Outdated Show resolved Hide resolved
Sources/SwiftGRPC/Core/ClientNetworkMonitor.swift Outdated Show resolved Hide resolved
Sources/SwiftGRPC/Core/ClientNetworkMonitor.swift Outdated Show resolved Hide resolved
Sources/SwiftGRPC/Core/ClientNetworkMonitor.swift Outdated Show resolved Hide resolved
@rebello95
Copy link
Collaborator Author

Thanks for all the great feedback @MrMage! Updated.

Copy link
Collaborator

@MrMage MrMage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but a few more comments.

Sources/SwiftGRPC/Core/ClientNetworkMonitor.swift Outdated Show resolved Hide resolved
Sources/SwiftGRPC/Core/ClientNetworkMonitor.swift Outdated Show resolved Hide resolved
Copy link
Collaborator

@MrMage MrMage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done; will merge once CI is happy and #357 is merged.

@rebello95
Copy link
Collaborator Author

@MrMage thanks. I’m happy to merge manually after that other PR goes in - want to do a couple final checks with this branch on my end.

@MrMage
Copy link
Collaborator

MrMage commented Mar 1, 2019

@rebello95 alright, merge at your convenience!

@rebello95 rebello95 merged commit 3b3c5c5 into grpc:master Mar 1, 2019
@rebello95 rebello95 deleted the client-connectivity branch March 1, 2019 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants