Skip to content

[HOLD for payment 2024-09-16] [$250] Account Settings- App freezes after sending a log file #47509

Closed

Description

@IuliiaHerets

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: v9.0.20-6
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/4859439
Issue reported by: Applause Internal Team

Action Performed:

  1. Go to Account Settings -> Troubleshoot
  2. Enable "Client side logging"
  3. Press "View debug console"
  4. Press "Share log"
  5. Press on any conversation

Expected Result:

The user should be moved to the report and logs should be sent as an attachment.
The app is stable and functional to return to the previous screen or access the user's profile.

Actual Result:

The user is moved to the report and logs are sent as an attachment.
The back button and the user's profile function become unresponsive. The app sometimes crashes after a few minutes.

Workaround:

Unknown

Platforms:

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

Screenshots/Videos

Log_1508.txt

Bug6573040_1723736646284.Sending_log_file.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~016f26106fe45b6825
  • Upwork Job ID: 1825662708863963045
  • Last Price Increase: 2024-08-19
  • Automatic offers:
    • suneox | Reviewer | 103607773
    • dominictb | Contributor | 103607774
Issue OwnerCurrent Issue Owner: @strepanier03

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Aug 15, 2024
  2. melvin-bot commented on Aug 15, 2024

    @melvin-bot

    Triggered auto assignment to @strepanier03 (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.

  3. IuliiaHerets commented on Aug 15, 2024

    @IuliiaHerets
    Author

    We think that this bug might be related to #wave-collect RELEASE 1

  4. IuliiaHerets commented on Aug 15, 2024

    @IuliiaHerets
    Author

    @strepanier03 FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

  5. changed the title [-]mWeb-Account Settings- App freezes after sending a log file[/-] [+]Account Settings- App freezes after sending a log file[/+] on Aug 15, 2024
  6. dominictb commented on Aug 19, 2024

    @dominictb
    Contributor

    Edited by proposal-police: This proposal was edited at 2023-10-02T10:00:00Z.

    Proposal

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

    Step to reproduce the issue (aside from OP's step)

    • Open app
    • Try to send an .txt attachment (One way to obtain it is exporting the onyx client log in Troubleshooting menu)
    • Observe that the app freeze / crash (sometimes), and in the console infinite errors happen
    image image

    What is the root cause of that problem?

    We are trying to add log to Onyx in here, but the extraData can be non-serializable. One possible way that the extraData is non-serializable is due to this, as in this case, the request contains a File-type field.

    The problem is that at first, the file field in AddAttachment API request params is still serializable (doesn't contain arraybuffer/stream data type), hence the request data is somehow persisted in Onyx (both in cache storage and in keyvalue store). However, after the request data is added to the FormData and sent, the file object now contains arrayBuffer and other binary/stream types which is non-serializable, hence making the addLog Onyx operation to fail.

    We can explain the non-stop error message log by following: Since the request is thrown in a promise chain without a proper catch, it will bubble up to the

    if (typeof event.reason === 'object' && event.reason !== null) {
    , which again trying to produce another log and added it to Onyx. The problem is, the current Onyx pre-merged value for the OnyxKeys.Log field contains File-type data in the cache, and Onyx is trying to set the merged data (including the File data in the indexedDB storage -> causing it the serializable issue as described in the screenshot above)., and the error will bubble back to the ErrorBoundary -> infinite circle.

    Extra note: Theoretically, we also encounter this issue while persisting AddAttachment request in Onyx storage, but it's hardly reproducible, and we see in practice that at first, the File object is still serializable, but then once the request is successfully executed, it will be removed forever, hence, the File object doesn't entail in the Onyx cache, causing further issue for subsequent merge/mergeCollection operations. However, with logging in Onyx, it is File object is still in the cache for a while, hence subsequent merge/mergeCollections will bump into this error.

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

    We should try to serialize the request.data before adding to the log. A holistic function can be enough. We can add more support for some special data type like File or Blob, or tune the implementation details based on our needs.

    // in @libs/Middleware/Logging.ts
    
    function serializeValue(value: any): string {
        const seen = new WeakSet();
      
        function serialize(item: any): any {
          // Handle primitive types
          if (item === undefined || item === null) return item
          if (typeof item === "number" || typeof item === "boolean") return item
          if (typeof item === "string") return item
      
          // Handle special objects
          if (item instanceof Date) return item;
          if (item instanceof RegExp) return item;
      
          // Handle arrays
          if (Array.isArray(item)) {
            if (seen.has(item)) return "\"[Circular]\"";
            seen.add(item);
            const serializedArray = item.map(serialize);
            seen.delete(item);
            return serializedArray;
          }
      
          // Handle objects
          if (typeof item === "object") {
            if (seen.has(item)) return "\"[Circular]\"";
            seen.add(item);
            const entries = Object.fromEntries(Object.entries(item).map(([key, val]) => [key, serialize(val)]));
            seen.delete(item);
            return entries;
          }
      
          // Handle functions and other non-serializable types
          const type = item.constructor.name || Object.prototype.toString.call(item).slice(8, -1);
          return `"[Not serializable: ${type}]"`;
        }
      
        return serialize(value);
      }
    
    function logRequestDetails(message: string, request: Request, response?: Response | void) {
        ....
        const extraData: Record<string, unknown> = {};
        /**
         * We don't want to log the request and response data for AuthenticatePusher
         * requests because they contain sensitive information.
         */
        if (request.command !== 'AuthenticatePusher') {
            extraData.request = {
                ...request,
                data: request.data,
            }
            extraData.response = response;
        }
    
        Log.info(message, false, logParams, false, extraData);
    }

    What alternative solutions did you explore? (Optional)

  7. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Aug 19, 2024
  8. changed the title [-]Account Settings- App freezes after sending a log file[/-] [+][$250] Account Settings- App freezes after sending a log file[/+] on Aug 19, 2024
  9. melvin-bot commented on Aug 19, 2024

    @melvin-bot
  10. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Aug 19, 2024
  11. melvin-bot commented on Aug 19, 2024

    @melvin-bot

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

  12. 23 remaining items

  13. suneox commented on Sep 24, 2024

    @suneox
    Contributor

    Bugzero Checklist

    • [@suneox] The PR that introduced the bug has been identified. Link to the PR: feat: log network response and request with filter options in debug console #45769
    • [@suneox] 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
    • [@suneox] 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: N/A
    • [@suneox] Determine if we should create a regression test for this bug: N/A: This issue has handled an edge case when updating the log request.​
  14. suneox commented on Sep 24, 2024

    @suneox
    Contributor

    @strepanier03 The checklist is completed, and we can proceed with the payment.​

  15. dominictb commented on Sep 30, 2024

    @dominictb
    Contributor

    @puneetlath Since this is awaiting payment. Can you remove the Monthly and Reviewing labels and add Daily?

  16. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed
    ReviewingHas a PR in review
    on Oct 1, 2024
  17. trjExpensify commented on Oct 1, 2024

    @trjExpensify
    Contributor

    Done that for you, @dominictb.

  18. melvin-bot commented on Oct 4, 2024

    @melvin-bot

    @puneetlath, @strepanier03, @suneox, @dominictb Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  19. puneetlath commented on Oct 6, 2024

    @puneetlath
    Contributor

    @strepanier03 looks like this is awaiting payment from you.

  20. strepanier03 commented on Oct 7, 2024

    @strepanier03
    Contributor

    Both contracts paid and closed with feedback left. I was OoO for a bit and this came due during that time, then the Hold status had it hidden from me and I missed it. Thank you for the bumps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions