App icon indicating copy to clipboard operation
App copied to clipboard

HIGH: [API Reliability] Fix extraneous `ReconnectApp` on refresh

Open quinthar opened this issue 1 year ago • 5 comments

Being discussed here: https://expensify.slack.com/archives/C049HHMV9SM/p1714059210537139

Often occurs in conjunction with HIGH: [Reliability] [$500] Multiple calls to GetNewerActions on report open and HIGH: [API Reliability] [$250] Multiple calls to OpenReport on signin, but seems to be a different root cause.

Actions Performed:

  1. Go to staging.new.expensify.com and login
  2. Open any report
  3. Refresh the page
  4. Observe the API calls for the OpenApp ReconnectApp and OpenReport

Expected Result:

There should be only one ReconnectApp OpenReport OpenApp calls

Actual Result:

Multiple calls for ReconnectApp OpenReport

Platforms:

Mac OS: Chrome/Safari

Screenshots/Videos:

image (15)

image (14) image (13)

quinthar avatar Apr 25 '24 15:04 quinthar

Hey Edu here from Callstack

gedu avatar Apr 25 '24 19:04 gedu

Updates on the OpenReport call case

Problems

There are 2 cases that I’m trying to prevent:

  1. Multiple calls given different scenarios, happy path (opening the report) and multiple ReportScreen creation (navigating to the report, maybe a refresh) all happening at the same time

  2. Updates on the multiple created ReportScreen, changing to another Report all reports gets updated

Solution

  1. I’m storing a set of the ReportsID calling the openReport so if the reportID is already fetching no need to call it again -> it gets removed when the response comes back

  2. I’m checking if the url reportID matches the active reportID (there always 1 report active), if it is active I can call the openReport

At least for now seems to be working, I'm testing and soon I can make a formal proposal or a PR if you want

gedu avatar Apr 26 '24 16:04 gedu

I don't think that's the right solution -- we don't want to suppress multiple calls, we want to figure out why the code is even attempting to make multiple calls, and stop it.

quinthar avatar Apr 27 '24 20:04 quinthar

actually, is this a dupe of: https://github.com/Expensify/App/issues/39673? Can we close this?

quinthar avatar Apr 27 '24 21:04 quinthar

Actually, the OpenReport portion of this seems like a dupe; let's reduce the scope of this issue to just be fixing the extraneous calls to ReconnectApp, ok @gedu ?

quinthar avatar Apr 27 '24 21:04 quinthar

@quinthar ok, The "suppress" is mainly because we create multiple ReportScreen, and even when you switch a report I saw OpenReport being called multiple times.
I will take a look at ReconnectApp

gedu avatar Apr 29 '24 05:04 gedu

@quinthar Looking at the code, when the site gets refreshed first it does the normal walk through, checking if the user was logged in already, which is true so it does a reconnectApp

Problem

On the other hand, the app register to the Network status, when it is registered it receives updates NetwokrConnection.ts file subscribeToNetInfo function

NetInfo.addEventListener((state) => {
   // code
   setOfflineStatus((state.isInternetReachable ?? false) === false);
   });

Given that isInternetReachable is null for a couple of calls before getting the right value, it triggers the reconnection. Screenshot 2024-04-29 at 12 11 31

Solution

Given that the Lib for web is still experimental and in the description for isInternetReachable if it is unknown is null. Also checking the code for web they send basic information until they collect the real

 const baseState = {
    isInternetReachable: null,
  };

  // If we don't have a connection object, we return minimal information

I suggest to remove the ?? false because we only care when the isInternetReachable has a value and the Lib has created a connection object with the data in it.

gedu avatar Apr 29 '24 11:04 gedu

I'm temporarily out of the C+ team as I'm about to go OOO, so the auto-assigning isn't working here. Tagging @tgolen on the PR to give it a quick review, otherwise once a BZ is assigned maybe they can find someone?

jjcoffee avatar May 06 '24 09:05 jjcoffee

Job added to Upwork: https://www.upwork.com/jobs/~01008cff119674ebe1

melvin-bot[bot] avatar May 06 '24 15:05 melvin-bot[bot]

Triggered auto assignment to Contributor Plus for review of internal employee PR - @s77rt (Internal)

melvin-bot[bot] avatar May 06 '24 15:05 melvin-bot[bot]

Triggered auto assignment to @dylanexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

melvin-bot[bot] avatar May 06 '24 15:05 melvin-bot[bot]

Sorry @s77rt , needed to assign to BZ and @jjcoffee as C+ , @jjcoffee is OOO soon so he's off the GH C+ team.

mallenexpensify avatar May 06 '24 15:05 mallenexpensify

Hiya! @mallenexpensify mind confirming what's needed here?

dylanexpensify avatar May 14 '24 12:05 dylanexpensify

@dylanexpensify The PR hasn't hit staging yet, but eventually payment will be due for C+ review.

jjcoffee avatar May 15 '24 09:05 jjcoffee

What's the next step here? Who's doing it? What is the ETA?

muttmuure avatar May 20 '24 10:05 muttmuure

So we just need to pay this out?

muttmuure avatar May 20 '24 11:05 muttmuure

Yep this was only deployed to staging so far though

mountiny avatar May 20 '24 17:05 mountiny

Still waiting then!

dylanexpensify avatar May 21 '24 18:05 dylanexpensify

Hit prod on 23rd, tomorrow will pay out!

dylanexpensify avatar May 29 '24 07:05 dylanexpensify

Payment Summary

Upwork Job

  • Contributor: @gedu is from an agency-contributor and not due payment
  • ROLE: @jjcoffee paid $(AMOUNT) via Upwork (LINK)

BugZero Checklist (@dylanexpensify)

  • [ ] I have verified the correct assignees and roles are listed above and updated the neccesary manual offers
  • [ ] I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants/1787505314359492608/hired)
  • [ ] I have paid out the Upwork contracts or cancelled the ones that are incorrect
  • [ ] I have verified the payment summary above is correct

melvin-bot[bot] avatar May 30 '24 18:05 melvin-bot[bot]

@dylanexpensify Friendly bump for payment :bow:

jjcoffee avatar Jun 04 '24 08:06 jjcoffee

Sorry, on it now! Thanks @jjcoffee!

dylanexpensify avatar Jun 05 '24 09:06 dylanexpensify

Invited to apply!

dylanexpensify avatar Jun 05 '24 09:06 dylanexpensify

@dylanexpensify Thank you, I've applied! :pray:

jjcoffee avatar Jun 05 '24 11:06 jjcoffee

@dylanexpensify Friendly bump :bow:

jjcoffee avatar Jun 10 '24 08:06 jjcoffee

@jjcoffee sent offer, sorry!

dylanexpensify avatar Jun 11 '24 10:06 dylanexpensify

@dylanexpensify No worries! I've accepted the offer now.

jjcoffee avatar Jun 11 '24 12:06 jjcoffee

done!

dylanexpensify avatar Jun 11 '24 12:06 dylanexpensify