App icon indicating copy to clipboard operation
App copied to clipboard

[HOLD for payment 2022-01-21] [$1000] When sending new chats in Desktop, an old message persists at the bottom

Open mallenexpensify opened this issue 5 years ago β€’ 34 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Action Performed:

  1. Open the desktop app
  2. Switch wifi network from home to tethering
  3. Send some messages

Expected Result:

New messages should always display at the bottom.

Actual Result:

When sending new chats in Desktop, an old message persists (is stuck) at the bottom.

Workaround:

Hard refreshing used to solve the problem but it's not now (at least not consistently on desktop). A user needs to log out/in to fix

Platform:

Where is this issue occurring?

Web iOS Android Desktop App βœ”οΈ Mobile Web

Version Number: Version 1.1.7-24

Notes/Photos/Videos: Switch wifi network from my home network to tethering from my phone, then send messages.

https://user-images.githubusercontent.com/22508304/137968945-91237105-29d9-4c9a-982f-9af4a362bf6b.mp4

Original issue is https://github.com/Expensify/App/issues/3623#, it got messy so I created this fresh one.

Logs: image

Expensify/Expensify Issue URL:

View all open jobs on Upwork


From @mallenexpensify https://expensify.slack.com/archives/C01GTK53T8Q/p1623805090370500

When sending new chats in Desktop, an old message persists at the bottom.

mallenexpensify avatar Oct 19 '21 18:10 mallenexpensify

Triggered auto assignment to @conorpendergrast (AutoAssignerTriage), see https://stackoverflow.com/c/expensify/questions/4749 for more details.

MelvinBot avatar Oct 19 '21 18:10 MelvinBot

Triggered auto assignment to @Gonals (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

MelvinBot avatar Oct 19 '21 18:10 MelvinBot

@isagoico Can you do me a favor and see if you can reproduce based on my steps above?

mallenexpensify avatar Oct 19 '21 19:10 mallenexpensify

Triggered auto assignment to @kadiealexander (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

MelvinBot avatar Oct 20 '21 09:10 MelvinBot

Huh... This is 4 days overdue. Who can take care of this?

MelvinBot avatar Oct 25 '21 19:10 MelvinBot

@isagoico Can you do me a favor and see if you can reproduce based on my steps above?

mallenexpensify avatar Oct 27 '21 15:10 mallenexpensify

@mallenexpensify Still unable to reproduce this on my side on the Desktop app

isagoico avatar Oct 27 '21 23:10 isagoico

Eep! 4 days overdue now. Issues have feelings too...

MelvinBot avatar Nov 01 '21 19:11 MelvinBot

Triggered auto assignment to @johnmlee101 (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.

MelvinBot avatar Nov 01 '21 21:11 MelvinBot

Thanks @isagoico , I'm going to move this forward since I was able to reproduce on my end (I had to switch between two wifi networks and not wifi>tethering) . Job is https://www.upwork.com/jobs/~01d220c10b9ea6bad2 Started at $500 since this has been a persistent issue (but... now with a new cleanish GH issue)

mallenexpensify avatar Nov 01 '21 21:11 mallenexpensify

I see your video and pic of the error. data you pass from an array. In the array, we pass data in a specific position. In your project, the array cannot pick data in a specific position so that's why this problem occurred. But when I see the code and then I will tell you the actual issue.

ahramay avatar Nov 02 '21 21:11 ahramay

Doubled price to $1000 https://www.upwork.com/jobs/~01d220c10b9ea6bad2

Also... We are placing all non-critical issues on hold while we're on a company offsite. The hold is expected to be lifted on 11/19 (but could go longer). For any PRs that are submitted before or during the hold, we will add a $250 bonus payment.

mallenexpensify avatar Nov 08 '21 17:11 mallenexpensify

@ahramay Did you figure out the cause with a proposed solution?

johnmlee101 avatar Nov 17 '21 19:11 johnmlee101

Why is it happening

When we send actions we naturally add them to the bottom even before the backend responds (optimistic updates)

https://github.com/Expensify/App/blob/f5a1b58d1aeeb804f23f9b1d6769b6ef25e57872/src/libs/actions/Report.js#L1071-L1073

Note we don't have any special (.catch) error handling for the call to API.Report_AddComment here

https://github.com/Expensify/App/blob/f5a1b58d1aeeb804f23f9b1d6769b6ef25e57872/src/libs/actions/Report.js#L1105-L1127

We have a .then block that would only handle a 408 error code

Meaning that we're relying on the standard error handling procedure. Which handles two cases:

A response arrived from the backend - we handle codes 407, 405, 404

https://github.com/Expensify/App/blob/f5a1b58d1aeeb804f23f9b1d6769b6ef25e57872/src/libs/API.js#L156-L185

In case of 407 we re authenticate and retry the request

A response didn't arrive or the request failed half way through

https://github.com/Expensify/App/blob/f5a1b58d1aeeb804f23f9b1d6769b6ef25e57872/src/libs/API.js#L187-L199

Following these facts we can see that:

  • we're only clearing/replacing optimistic actions when the backend responds to a request
  • we're only retrying requests when: it started while we were offline, or when it failed due to auth token 407.
  • we're not retrying the request if it failed without a response from the backend, like when the network is lost in the middle of the request
  • when that happens we have a data loss - nothing will re-post the Report_AddComment
  • the optimistic action will remain on the bottom of our chat - the only thing that can clear it now is logic inside fetchActions which usually happens during app startup https://github.com/Expensify/App/blob/f5a1b58d1aeeb804f23f9b1d6769b6ef25e57872/src/libs/actions/Report.js#L914-L916

This comment contains logs captured when the issue happened: https://github.com/Expensify/App/issues/2713#issuecomment-902137036

See Uncaught (in promise) Error: session.offlineMessageRetry It's resulting from the Report_AddComment getting rejected in the end

https://github.com/Expensify/App/blob/f5a1b58d1aeeb804f23f9b1d6769b6ef25e57872/src/libs/API.js#L197-L198

kidroca avatar Nov 21 '21 11:11 kidroca

Proposal

We have a shouldRetry flag on request that have to be resend, but it's only used to persist request that start when we're already offline https://github.com/Expensify/App/blob/f5a1b58d1aeeb804f23f9b1d6769b6ef25e57872/src/libs/Network.js#L178-L187

We can use it to retry the requests in case something unexpected happened in flight

src/libs/API.js

Network.registerErrorHandler((queuedRequest, error) => {
    if (queuedRequest.command !== 'Log') {
        LogUtil.hmmm('[API] Handled error when making request', error);
    } else {
        console.debug('[API] There was an error in the Log API command, unable to log to server!', error);
    }

    // Set an error state and signify we are done loading
    Session.setSessionLoadingAndError(false, 'Cannot connect to server');

    // When the request should be retried put it back to the queue
    // If we're online it'll get retried, otherwise be retried later
    if (lodashGet(queuedRequest, 'data.shouldRetry')) {
        Network.post(queuedRequest.command, queuedRequest.data, queuedRequest.type)
            .then(queuedRequest.resolve)
            .catch(queuedRequest.reject);

        return;
    }

    // Reject the queued request with an API offline error so that the original caller can handle it.
    queuedRequest.reject(new Error(CONST.ERROR.API_OFFLINE));
});

I propose to add this logic in general for all requests because we already decided to retry them if we were offline when they started, so it seems natural to also retry them in case we became offline in the middle of the request and received no backend response


Since handleExpiredAuthToken also has the same "retry request" logic, we should extract a retryRequest function to be called on both places where it's needed

kidroca avatar Nov 21 '21 11:11 kidroca

@johnmlee101 can you review @kidroca 's proposal above?

mallenexpensify avatar Nov 22 '21 19:11 mallenexpensify

Makes sense, I think handling "no response" cases seems like a good next progression of our network logic. Assigning @kidroca !

johnmlee101 avatar Nov 22 '21 20:11 johnmlee101

πŸ“£ @kidroca You have been assigned to this job by @johnmlee101! Please apply to this job in Upwork and let us know when we can expect a PR to be ready for review πŸ§‘β€πŸ’» Keep in mind: Code of Conduct | Contributing πŸ“–

MelvinBot avatar Nov 22 '21 20:11 MelvinBot

Should I be posting a comment here once I apply to Upwork?

It's not specified on https://github.com/Expensify/App/blob/main/CONTRIBUTING.md#propose-a-solution-for-the-job

If your solution proposal is accepted, Expensify will hire you on Upwork and assign the GitHub issue to you.

I've only been assigned the issue, but not been hired in upwork


Please apply to this job in Upwork and let us know when we can expect a PR to be ready for review πŸ§‘β€πŸ’»

Does that mean I should post a comment here or on Upwork? Because on the proposal form in Upwork there's:

What date do you estimate to be able to submit a pull request containing the fix for this issue?

kidroca avatar Nov 25 '21 19:11 kidroca

Jumping in while Matt's on leave.

@kidroca I see how this is confusing! I'll pass this feedback along to the team. Could you please leave a comment here with the expected completion time? I've gone ahead and hired you in Upwork.

kadiealexander avatar Nov 29 '21 04:11 kadiealexander