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

Reconnect the network when we switch network types #8034

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

larkox
Copy link
Contributor

@larkox larkox commented Jun 24, 2024

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

Improve connection behavior when switching network types (cell, wifi, vpn...).

@larkox larkox added the 2: Dev Review Requires review by a core commiter label Jun 24, 2024
Copy link
Contributor Author

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 larkox added the Do Not Merge Should not be merged until this label is removed label Jun 24, 2024
@enahum
Copy link
Contributor

enahum commented Sep 16, 2024

@larkox will you be making this changes permanent in the library, are we proceeding with this ?

@enahum enahum removed their request for review September 16, 2024 03:09
@larkox larkox marked this pull request as ready for review September 18, 2024 10:51
@larkox larkox added 3: QA Review Requires review by a QA tester and removed Do Not Merge Should not be merged until this label is removed labels Sep 18, 2024
@larkox
Copy link
Contributor Author

larkox commented Sep 18, 2024

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.

@larkox larkox requested a review from pvev September 18, 2024 10:52
Copy link
Contributor

@pvev pvev left a 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();
Copy link
Contributor

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?

Copy link
Contributor

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) {
    ...
  }

Copy link
Contributor Author

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();
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@larkox larkox removed the 2: Dev Review Requires review by a core commiter label Sep 24, 2024
@larkox
Copy link
Contributor Author

larkox commented Sep 24, 2024

@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.

@yasserfaraazkhan yasserfaraazkhan added the E2E iOS tests for PR Run iOS E2E Detox tests label Sep 24, 2024
@github-actions github-actions bot removed the E2E iOS tests for PR Run iOS E2E Detox tests label Sep 24, 2024
@yasserfaraazkhan yasserfaraazkhan added the Build Apps for PR Build the mobile app for iOS and Android to test label Sep 27, 2024
Copy link
Contributor

@yasserfaraazkhan yasserfaraazkhan left a 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

rn_image_picker_lib_temp_03bab33c-cae2-46e6-a3f1-ef05309afee5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3: QA Review Requires review by a QA tester Build Apps for PR Build the mobile app for iOS and Android to test release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants