-
Notifications
You must be signed in to change notification settings - Fork 58
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
Implement auto reconnect for WebSocketConnectionManager #318
Conversation
cced50b
to
8eb5e5d
Compare
Just observed this crash (occasionally) when trying to reconnect with no internet access.
According to this, it seems that this exception happens when there's no internet connection and needs to be caught manually. Will add that to this PR. |
final NetworkInfo info = connManager.getActiveNetworkInfo(); | ||
return info != null && info.isConnected(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rarely means that there is internet connectivity, unfortunately.
- The active network may be a WiFi network at a coffee shop that imposes a captive portal;
- The active network may be up, but not serving packets.
Consequently, it is better to just try network activities, and if they work, they work, if they fail, do exponential backoff with retries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that this doesn't necessarily mean there is internet connectivity but there is a chance, so IMHO trying once when a network becomes available doesn't hurt but can dramatically reduce the time needed to resume if there is internet access because of exponential backoff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. It was also pointed out to me that this is the existing behavior of the non-WebSocket branch, too.
Issue #, if available: #317
Description of changes:
Implemented auto reconnect for WebSocket-based subscriptions in WebSocketConnectionManager based on legacy implementation in
RealSubscriptionManager
.Also added result check for
WebSocket.send()
. This fixes the bug that further subscriptions after theWebSocketListener
'sonFailure
callback will fail silently because once failedWebSocket
s cannot be used any more.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.