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

[HOLD for payment 2024-02-26][$500] [MEDIUM] Erroring thumbnail images try to reload infinitely #34601

Closed
4 of 6 tasks
lindboe opened this issue Jan 16, 2024 · 58 comments
Closed
4 of 6 tasks
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering External Added to denote the issue can be worked on by a contributor

Comments

@lindboe
Copy link
Contributor

lindboe commented Jan 16, 2024

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


Version Number: 1.4.25-4
Reproducible in staging?: Yes
Reproducible in production?: It's worse on production, the app fails to load completely once I sign in.
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers): [email protected]
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @lindboe
Slack conversation: https://expensify.slack.com/archives/C01GTK53T8Q/p1705427206739379?thread_ts=1705360862.915459&cid=C01GTK53T8Q

Action Performed:

  1. Have a request with a receipt image that produces a 404 when requested. (I am not sure how to reproduce this part outside of development, where you can give a thumbnail component an intentionally wrong URL.)
  2. Open the app in a web browser and open the devtools. Observe that the requests for the image that can't be loaded are continuously made.

Expected Result:

After the request returns a 404, the requests should stop being made.

Actual Result:

Requests for the image are infinitely repeated.

Workaround:

If this issue is encountered in production in its current state, the app can't be used at all, although I believe that particular issue may have been fixed by @cead22.

If this issue is encountered in staging, I don't think this prevents usage.

In development, it causes a connection/file descriptor leak as webpack generates more and more connections it never clears. This eventually leads to the developer's computer encountering errors and not working properly, including affecting internet access. (This must also be caused by a second issue with the app not clearing closed connections correctly).

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

In development:

receipt404.mov

Production screenshot:
Screenshot 2024-01-16 at 10 57 26 AM

Root cause and considerations for proposals:

  1. Image, which handles the load request, is memoized based on whether the identity of the source prop stays the same
  2. ImageWithSizeCalculation is reconstructing source each render because it's creating the object in the prop. Pretty easy to fix with a useMemo instead:
    const source = useMemo(() => {
        return {uri: url};
    }, [url]);

This does NOT occur for the Image/index.native.js implementation.

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~010386784e89b6acc5
  • Upwork Job ID: 1749005349524606976
  • Last Price Increase: 2024-02-04
  • Automatic offers:
    • paultsimura | Contributor | 28145121
@lindboe lindboe added Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 labels Jan 16, 2024
Copy link

melvin-bot bot commented Jan 16, 2024

Triggered auto assignment to @jliexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@lindboe
Copy link
Contributor Author

lindboe commented Jan 16, 2024

Update: I've started to be able to load data on production again, now behavior matches staging/dev.

@jliexpensify
Copy link
Contributor

Hi @lindboe - cool, so all good here? Can I close this?

@lindboe
Copy link
Contributor Author

lindboe commented Jan 17, 2024

@jliexpensify I'm not sure I understand the question? The original bug still exists, if you're referring to my update, note that in the original ticket production was breaking worse than the other environments for me, in that it refused to load at all, but now all environments have the issue of constantly attempting to reload the 404ing image.

@jliexpensify
Copy link
Contributor

jliexpensify commented Jan 17, 2024

Sorry @lindboe I misread your comment as the issue was fixed. I'll re-review this and see if I can reproduce.

EDIT: I don't know how to repro step 1, so asking here: https://expensify.slack.com/archives/C01SKUP7QR0/p1705458078466679 and here: https://expensify.slack.com/archives/C01GTK53T8Q/p1705532780265849

@melvin-bot melvin-bot bot added the Overdue label Jan 19, 2024
@jliexpensify
Copy link
Contributor

@tranvantoan-qn responded and can reproduce the 404 request issue. Do you want to make a proposal in this GH?

@melvin-bot melvin-bot bot removed the Overdue label Jan 21, 2024
@jliexpensify jliexpensify added External Added to denote the issue can be worked on by a contributor Overdue labels Jan 21, 2024
Copy link

melvin-bot bot commented Jan 21, 2024

Job added to Upwork: https://www.upwork.com/jobs/~010386784e89b6acc5

@melvin-bot melvin-bot bot changed the title Erroring thumbnail images try to reload infinitely [$500] Erroring thumbnail images try to reload infinitely Jan 21, 2024
@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Jan 21, 2024
Copy link

melvin-bot bot commented Jan 21, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @parasharrajat (External)

@tranvantoan-qn
Copy link

tranvantoan-qn commented Jan 21, 2024

@jliexpensify Sorry, I'm not a developer (I used to be a test contributor when the program was still open to testers). However, I've experienced that trying to reproduce issues can sometimes be impossible due to different conditions, so using some support tools can be very helpful. If you want to know more about how to use these tools to mimic scenarios like this one, I'm happy to help.

Once we can reproduce it, either in a normal way or by using the tool, I'm sure that we can fix it and verify the solution

@paultsimura
Copy link
Contributor

paultsimura commented Jan 21, 2024

Proposal

Please re-state the problem that we are trying to solve in this issue.

When an image cannot be loaded, requests are constantly being made.

This can be easily (for now) reproduced when modifying the Distance request offline. The Distance receipt will be fixed in the #34287, but for now, it allows us to test this endless requests loop.

What is the root cause of that problem?

The root cause is in the ImageWithSizeCalculation component, which builds the source inside the render body:

So the component is re-rendered each time the request fails, and the request is sent again. This creates a loop.

What changes do you think we should make in order to solve the problem?

Instead of building the source in-place, we should use the useMemo hook:

const source = useMemo(() => ({uri: url}), [url]);

And use this source for the Image.source.

Then, we should handle the fallback image.
We've decided that it will depend on 2 things: network status and the image type (purpose).
For that, we should:

  1. Make use of the {isOffline} = useNetwork()
  2. Pass a new parameter type or purpose (or whatever) to the ImageWithSizeCalculation to indicate whether it's a receipt/attachment/file.

To display this fallbackImage, we will add a new var and will set it on the onError:

const hasFailedToLoadRef = useRef<boolean | null>(null);
const onError = () => {
        Log.hmmm('Unable to fetch image to calculate size', {url});
        hasFailedToLoadRef.current = true
};

Then, we'll need to alter the above-mentioned memo to handle the failed state:

const source = useMemo(() => {
  if (!hasFailedToLoadRef.current) {
    return {uri: url};
  }
  
  if (isOffline) {
    return OFFLINE_IMG;
  }

  return FALLBACK_BASED_ON_TYPE
}, [url, hasFailedToLoadRef, isOffline, type]);

The last thing would be to handle the network change: when coming back online after being offline, reset the hasFailedToLoadRef once to allow re-fetching of the image from the server.

What alternative solutions did you explore? (Optional)

@jliexpensify
Copy link
Contributor

Got it, thanks for the context @tranvantoan-qn! My biggest question is to understand how these 404 errors are generated and if they can be generated by actual users. The reason I ask is that we have pivoted to now focusing on project-specific bugs that impact performance/the UI so if it's going to affect actual users, we'd want to get it fixed. It's just unusual because I don't think anyone on our team, who use the app in real life, have experienced this with our requests.

@paultsimura
Copy link
Contributor

@jliexpensify I have described the easiest way to reproduce the issue at the moment:

This can be easily (for now) reproduced when modifying the Distance request offline. The Distance receipt will be fixed in the #34287, but for now, it allows us to test this endless requests loop.

#34601 (comment)

@jliexpensify
Copy link
Contributor

jliexpensify commented Jan 21, 2024

It looks like your proposal got posted as I was writing mine - it's great that we have a way to easily repro this one! If it's associated with Distance requests atm, we can fold this into #wave5 - https://expensify.slack.com/archives/C05DWUDHVK7/p1705872590528689

@parasharrajat
Copy link
Member

Proposal looks correct. I will do some testing on it and let you all know.

@jliexpensify jliexpensify moved this from Release 3: Migration for All to Release 5: Best in Class in [#whatsnext] Wave 05 - Deprecate Free Jan 23, 2024
@jliexpensify jliexpensify added Monthly KSv2 and removed Daily KSv2 labels Jan 23, 2024
@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 Overdue labels Feb 12, 2024
@allroundexperts
Copy link
Contributor

Can someone please assign this to me since I reviewed the PR? Thanks!

@jliexpensify
Copy link
Contributor

I assume we unassign @parasharrajat ?

@paultsimura
Copy link
Contributor

Deployed to prod: #36214 (comment)

@allroundexperts
Copy link
Contributor

Checklist

  1. Migrate Image/index.js to function component #24159
  2. https://github.com/Expensify/App/pull/24159/files#r1493106476
  3. N/A
  4. I think this was an edge case that is not easily reproducible without altering the generated HTML or the source code. As such, a regression test might not make complete sense here.

@jliexpensify jliexpensify changed the title [$500] Erroring thumbnail images try to reload infinitely [PAY FEB 22ND][$500] Erroring thumbnail images try to reload infinitely Feb 18, 2024
@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Feb 19, 2024
@melvin-bot melvin-bot bot changed the title [PAY FEB 22ND][$500] Erroring thumbnail images try to reload infinitely [HOLD for payment 2024-02-26] [PAY FEB 22ND][$500] Erroring thumbnail images try to reload infinitely Feb 19, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Feb 19, 2024
Copy link

melvin-bot bot commented Feb 19, 2024

Reviewing label has been removed, please complete the "BugZero Checklist".

Copy link

melvin-bot bot commented Feb 19, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.42-5 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-02-26. 🎊

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Feb 19, 2024

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@allroundexperts] The PR that introduced the bug has been identified. Link to the PR:
  • [@allroundexperts] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@allroundexperts] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [@allroundexperts] Determine if we should create a regression test for this bug.
  • [@allroundexperts] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@jliexpensify] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@jliexpensify jliexpensify changed the title [HOLD for payment 2024-02-26] [PAY FEB 22ND][$500] Erroring thumbnail images try to reload infinitely [HOLD for payment 2024-02-26][$500] Erroring thumbnail images try to reload infinitely Feb 20, 2024
@greg-schroeder greg-schroeder changed the title [HOLD for payment 2024-02-26][$500] Erroring thumbnail images try to reload infinitely [HOLD for payment 2024-02-26][$500] [MEDIUM] Erroring thumbnail images try to reload infinitely Feb 20, 2024
@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Feb 26, 2024
@jliexpensify
Copy link
Contributor

No checklist needed

Payment Summary:

@JmillsExpensify
Copy link

$500 approved for @allroundexperts based on summary above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering External Added to denote the issue can be worked on by a contributor
Projects
No open projects
Development

No branches or pull requests