Skip to content

[HOLD for payment 2024-02-05] [$500] SignInWithShortLivedAuthToken sometimes gets called in a loop #33413

Closed

Description

@flodnv

Version Number: all
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: n/a
Email or phone of affected tester (no customers): everyone it seems like
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL: https://expensify.slack.com/archives/C03TQ48KC/p1702405892791069
Issue reported by: Expensify
Slack conversation: https://expensify.slack.com/archives/C03TQ48KC/p1702405892791069

Action Performed:

We've seen several requests in our server logs where SignInWithShortLivedAuthToken is called in what seems like a loop, example:
image

2 more internal examples here:
https://github.com/Expensify/Expensify/issues/343028
https://github.com/Expensify/Expensify/issues/345424

Expected Result:

SignInWithShortLivedAuthToken should not be called dozens / hundreds of times in a row by the same user

Actual Result:

.

Workaround:

Can the user still use Expensify without this being fixed?

Not really, it requires us to manually delete the hundreds of logins, because they make the authentication unbearably slow.

Platforms:

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

I guess all

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

Screenshots/Videos

See above

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0127bcdf935f2ba4af
  • Upwork Job ID: 1737830869162020864
  • Last Price Increase: 2023-12-28
Issue OwnerCurrent Issue Owner: @kadiealexander

Activity

  1. added
    Daily
    Bug
    on Dec 21, 2023
  2. melvin-bot commented on Dec 21, 2023

    @melvin-bot

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

  3. melvin-bot commented on Dec 21, 2023

    @melvin-bot

    Bug0 Triage Checklist (Main S/O)

    • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
    • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
      • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
    • This bug is reproducible using the reproduction steps in the OP. S/O
      • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
      • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
    • This issue is filled out as thoroughly and clearly as possible
      • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
    • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync
  4. added
    External
    on Dec 21, 2023
  5. changed the title [-]SignInWithShortLivedAuthToken sometimes gets called in a loop[/-] [+][$500] SignInWithShortLivedAuthToken sometimes gets called in a loop[/+] on Dec 21, 2023
  6. melvin-bot commented on Dec 21, 2023

    @melvin-bot
  7. added
    Help Wanted
    on Dec 21, 2023
  8. melvin-bot commented on Dec 21, 2023

    @melvin-bot

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

  9. FitseTLT commented on Dec 21, 2023

    @FitseTLT
    Contributor

    Proposal

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

    SignInWithShortLivedAuthToken sometimes gets called in a loop

    What is the root cause of that problem?

    Inside signInWithShortLivedAuthToken we set isLoading of the account to true in the optimistic data here

    function signInWithShortLivedAuthToken(email: string, authToken: string) {
    const optimisticData: OnyxUpdate[] = [
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: ONYXKEYS.ACCOUNT,
    value: {
    ...CONST.DEFAULT_ACCOUNT_DATA,
    isLoading: true,
    },
    },

    but there are places where we have called signInWithShortLivedAuthToken without checking account.isLoading is false
    like here
    Session.signInWithShortLivedAuthToken(email, shortLivedAuthToken);

    so signInWithShortLivedAuthToken can be called repeatedly and redundant requests can be sent to the server if for e.g the useEffect is called repeatedly with a change of dependency.

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

    We should call signInWithShortLivedAuthToken after checking account.isLoading is false everywhere we are using it to avoid requesting in a loop

    Session.signInWithShortLivedAuthToken(email, shortLivedAuthToken);

    and also in here

    Session.signInWithShortLivedAuthToken(credentials.login, shortLivedAuthToken);
    }

    if (!props.account.isLoading) {
                        Session.signInWithShortLivedAuthToken(email, shortLivedAuthToken);
                    }
    

    as we did here

    if (shortLivedAuthToken && !props.account.isLoading) {
    Session.signInWithShortLivedAuthToken(email, shortLivedAuthToken);
    return;

    What alternative solutions did you explore? (Optional)

  10. AmjedNazzal commented on Dec 21, 2023

    @AmjedNazzal
    Contributor

    @flodnv Is there a particular action showing on your end where this loop happens? I've tried opening a WS from OD while ND is logged out and while it's logged in with a different user and I'm seeing only one SignInWithShortLivedAuthToken call being made
    shortauth

  11. flodnv commented on Dec 21, 2023

    @flodnv
    ContributorAuthor

    @flodnv Is there a particular action showing on your end where this loop happens?

    Honestly I'm not sure 😬

  12. flodnv commented on Dec 22, 2023

    @flodnv
    ContributorAuthor

    @Santhosh-Sellavel please let us know what you think about the proposal 🙇

  13. 69 remaining items

  14. changed the title [-] [$500] SignInWithShortLivedAuthToken sometimes gets called in a loop[/-] [+][HOLD for payment 2024-02-05] [$500] SignInWithShortLivedAuthToken sometimes gets called in a loop[/+] on Jan 29, 2024
  15. removed
    Reviewing
    on Jan 29, 2024
  16. melvin-bot commented on Jan 29, 2024

    @melvin-bot

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

  17. melvin-bot commented on Jan 29, 2024

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.32-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-05. 🎊

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

  18. melvin-bot commented on Jan 29, 2024

    @melvin-bot

    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:

  19. Santhosh-Sellavel commented on Feb 2, 2024

    @Santhosh-Sellavel
    Collaborator

    @arosiclair Can you help me with the checklist here?

  20. arosiclair commented on Feb 5, 2024

    @arosiclair
    Contributor

    Instead of adding regressions tests we are probably going to add rate limiting to this endpoint to prevent this in the future. Checklist should be all set @kadiealexander @Santhosh-Sellavel

  21. added
    Daily
    and removed
    Weekly
    on Feb 5, 2024
  22. melvin-bot commented on Feb 5, 2024

    @melvin-bot

    Payment Summary

    Upwork Job

    BugZero Checklist (@kadiealexander)

    • 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/1737830869162020864/hired)
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  23. kadiealexander commented on Feb 7, 2024

    @kadiealexander
    Contributor

    Closing, please request your payment in NewDot Santhosh!

  24. Santhosh-Sellavel commented on Feb 10, 2024

    @Santhosh-Sellavel
    Collaborator

    Requested on ND

  25. JmillsExpensify commented on Feb 11, 2024

    @JmillsExpensify
    Contributor

    $500 approved for @Santhosh-Sellavel based on summary above.

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

Metadata

Metadata

Labels

Awaiting PaymentBugDailyInternal

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions