-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Reconnect the network when we switch network types #8034
base: main
Are you sure you want to change the base?
Conversation
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 change has to be made in the library. I added it here just for visibility and to agree on whether this is the desired change.
@larkox will you be making this changes permanent in the library, are we proceeding with this ? |
After discussing with @enahum we are going to move forward with this change on the patch. That way, if something fails, the revert is way simpler. If we see this solve the issue and doesn't bring any unexpected behavior, we can make the change in the library. |
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.
LGTM! thanks @larkox . Just posted a couple of questions.
@@ -43,7 +44,9 @@ class WebsocketManager { | |||
} | |||
|
|||
public init = async (serverCredentials: ServerCredential[]) => { | |||
this.netConnected = Boolean((await NetInfo.fetch()).isConnected); | |||
const netInfo = await NetInfo.fetch(); |
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.
would it be worth or necessary to handle any potential error in the case of a promise rejection?
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.
the worse case here is if the fetch() timed-out, which is default at 15s. I wonder how often is that happening and how badly backed up is the JS thread to not get any response in 15s.
But could just safely change:
if (netInfo) {
...
}
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.
Since this code has been like this for a long while and (seemingly) never got us any problem, I will leave it as is for readability sake.
// Close all connections when we switch from (for example) vpn to wifi | ||
// to ensure we are using the right network and doesn't get stuck on | ||
// retries. | ||
this.closeAll(); |
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.
wondering if it would make sense to set here some sort of debounce time here. I say in case of potential network fluctuation.
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.
You mean the network quickly moves between, let's say, wifi and cell?
I don't expect that to happen often, but it is something we could consider. @rahimrahman thoughts on this?
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.
0/5. I know you can toggle the Wifi switch back and forth quickly, but I doubt that it will get picked up by netinfo to worry about putting a debounce.
@yasserfaraazkhan The important part of this PR is to test changing between different kinds of connection (cell, wifi, vpn...) and see if the connection is restablished relatively fast. |
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.
Hi @larkox ,
I've tested this with VPN+Cellular, VPN+wifi, wifi, cellular.
the server connected was establish fast. Did not see 'No connection' message in these flow for long time.
there is one scenario, I want to share.
- If we connect to VPN. (have wifi or Cellular data connection)
- While the app is open.
- Turn off the Wifi or cellular data connection (let the VPN connect still be)
- Observe the ssl error on mattermost app
Summary
When network switches (cell -> wifi for example) the network doesn't get disconnected, disconnecting the websockets.
In certain circumstances, this may lead to delays in reconnecting the websocket.
Ticket Link
May fix https://mattermost.atlassian.net/browse/MM-57692
Release Note