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

[PAID, WAITING ON SITU FOR CHECKLIST] [$500] Account - Account is not simultaneously signed out on secondary device when closing account #36632

Closed
1 of 6 tasks
lanitochka17 opened this issue Feb 15, 2024 · 34 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@lanitochka17
Copy link

lanitochka17 commented Feb 15, 2024

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: 1.4.42-1
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers): natnael.expensify+3@gmail.com
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause - Internal Team
Slack conversation:

Action Performed:

  1. Sign in to main device and secondary device with the same account
  2. Close account on main device
  3. Navigate to secondary device

Expected Result:

  • Account should be signed out on the secondary device simultaneously
  • There should be 'Account closed successfully' message under email input field
  • There shouldn't be console log error

Actual Result:

  • Account is not signed out before user interacts with the account
  • There is no 'Account closed successfully' message under email input field
  • There is console log error

Workaround:

Unknown

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

Add any screenshot/video evidence

Bug6381147_1708026494674.Screen_Recording_2024-02-14_at_2.10.57_at_night.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~011fa63892ed79f932
  • Upwork Job ID: 1758227147283243008
  • Last Price Increase: 2024-02-22
  • Automatic offers:
    • situchan | Reviewer | 0
    • wildan-m | Contributor | 0
@lanitochka17 lanitochka17 added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Feb 15, 2024
@melvin-bot melvin-bot bot changed the title Account - Account is not simultaneously signed out on secondary device when closing account [$500] Account - Account is not simultaneously signed out on secondary device when closing account Feb 15, 2024
Copy link

melvin-bot bot commented Feb 15, 2024

Job added to Upwork: https://www.upwork.com/jobs/~011fa63892ed79f932

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Feb 15, 2024
Copy link

melvin-bot bot commented Feb 15, 2024

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

Copy link

melvin-bot bot commented Feb 15, 2024

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

@brandonhenry
Copy link
Contributor

Proposal

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

When an account is closed on one device, the account does not simultaneously sign out on a secondary device. Additionally, there is no "Account closed successfully" message displayed under the email input field on the secondary device, and there is an error logged in the console.

What is the root cause of that problem?

The root cause appears to be a lack of real-time session management across multiple devices. The current system does not seem to notify or force logout on all active sessions once an account is closed. This might be due to the session tokens not being invalidated across the system or the secondary device not polling for session validity in real-time.

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

  • Implement a push notification system that informs all active sessions when an account is closed, prompting immediate sign out.
  • Invalidate the session tokens at the server level once an account closure action is initiated, preventing further API calls from a closed account.
  • Ensure that the secondary device listens for account status changes and responds accordingly by signing the user out and displaying the appropriate account closure message.
  • Address the console log error by ensuring proper error handling and messaging across the application.

What alternative solutions did you explore? (Optional)

An alternative approach could involve periodically checking the validity of the session token against the server, but this could introduce unnecessary network requests and latency. Maybe do so but with a max retry count.

Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

@wildan-m
Copy link
Contributor

wildan-m commented Feb 17, 2024

Proposal

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

What is the root cause of that problem?

1. There is console log error

When an account is closed, it will return this Onyx update:

    {
        "onyxMethod": "clear"
    },

It lacks a key property.

This code call includes no null check.

const reportActionsOnly = pushJSON.filter((update) => update.key.includes('reportActions_'));

2. Account is not signed out before user interacts with the account

This process is blocked by the first issue

3. There is no 'Account closed successfully' message under email input field

This behavior is blocked by the first issue

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

Add a null check to the key property.
Change:

const reportActionsOnly = pushJSON.filter((update) => update.key.includes('reportActions_'));

to

    const reportActionsOnly = pushJSON.filter((update) => update.key?.includes('reportActions_'));

Why would adding a null check automatically resolve the second and third issues?

This is the updated onyx information from the server on the secondary device:

[
    {
        "onyxMethod": "clear"
    },
    {
        "key": "preferredLocale",
        "onyxMethod": "merge",
        "value": "en"
    },
    {
        "key": "closeAccount",
        "onyxMethod": "merge",
        "value": {
            "success": "Account closed successfully"
        }
    },
    {
        "key": "isCheckingPublicRoom",
        "onyxMethod": "set",
        "value": false
    }

"onyxMethod": "clear" will call Onyx.clear() and remove all onyx data, including session.authToken.

Clearing the authToken will trigger a re-render on the isAuthenticated props.

const isAuthenticated = useMemo(() => Boolean(lodashGet(props.session, 'authToken', null)), [props.session]);

The isAuthenticated === false condition will redirect the user to the default public screens (Sign in page).

if (authenticated) {
const AuthScreens = require('./AuthScreens').default;
// These are the protected screens and only accessible when an authToken is present
return <AuthScreens />;
}
const PublicScreens = require('./PublicScreens').default;

In addition to redirecting, it will also trigger necessary cleaning tasks for sign-out.

return () => {
unsubscribeShortcutsOverviewShortcut();
unsubscribeSearchShortcut();
unsubscribeChatShortcut();
Session.cleanupSession();
};

Why should we not call the signOut function on a secondary device?

It will cause an error as the logout API is cancelled, possibly due to a user's removed object that no longer exists.
Screenshot 2024-02-22 at 09 23 38

Is there any difference between signing out from Onyx.clear and Session.signOut function?

Yes, cleanupSession is missing two cleanup tasks in comparison to Session.signOut. To resolve this, we can transfer these cleaning tasks from Session.signOut to cleanupSession.

Move:

clearCache().then(() => {
Log.info('Cleared all cache data', true, {}, true);
});
Timing.clearData();

To

/**
 * Put any logic that needs to run when we are signed out here. This can be triggered when the current tab or another tab signs out.
 * - Cancels pending network calls - any lingering requests are discarded to prevent unwanted storage writes
 * - Clears all current params of the Home route - the login page URL should not contain any parameter
 */
function cleanupSession() {
    Pusher.disconnect();
    Timers.clearAll();
    Welcome.resetReadyCheck();
    PriorityMode.resetHasReadRequiredDataFromStorage();
    MainQueue.clear();
    HttpUtils.cancelPendingRequests();
    PersistedRequests.clear();
    NetworkConnection.clearReconnectionCallbacks();
    SessionUtils.resetDidUserLogInDuringSession();
    resetHomeRouteParams();
    clearCache().then(() => {
        Log.info('Cleared all cache data', true, {}, true);
    });
    Timing.clearData();
}

This way, cleanup tasks will be consistent for both methods.

Branch to test.

What alternative solutions did you explore? (Optional)

Alternative 1 -- add checkCloseAccount check

function playSoundForMessageType(pushJSON: OnyxServerUpdate[]) {
    if(checkCloseAccount(pushJSON)){
       return;
   }
.....

function checkCloseAccount(jsonData) {
    return _.some(jsonData, item => item.key === "closeAccount");
}

Alternative 2 -- Provide onyx update return with some key. e.g.

    {
        "key": "clear"
        "onyxMethod": "clear"
    },

Result

GMT20240219-125319_Clip_Wildan.M.s.Clip.02_19_2024.mp4

@wildan-m
Copy link
Contributor

Proposal Updated

Add alternative solutions

@suneox
Copy link
Contributor

suneox commented Feb 17, 2024

Proposal

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

Account - Account is not simultaneously signed out on secondary device when closing account

What is the root cause of that problem?

When the second device receives the event closeAccount from socket at this line we don't handle logout.

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

We will check if the event include CLOSE_ACCOUNT_FORM and process to sign out

    PusherUtils.subscribeToMultiEvent(Pusher.TYPE.MULTIPLE_EVENT_TYPE.ONYX_API_UPDATE, (pushJSON: OnyxServerUpdate[]) => {
+       const onyxCloseAccount = pushJSON.find((update) => update.key === ONYXKEYS.FORMS.CLOSE_ACCOUNT_FORM);
+       if (onyxCloseAccount) {
+           Session.signOutAndRedirectToSignIn();
+           return Onyx.update([onyxCloseAccount]);
+       }
        playSoundForMessageType(pushJSON);
POC
  • Account should be signed out on the secondary device simultaneously
  • There should be 'Account closed successfully' message under email input field
  • There shouldn't be console log error
Screen.Recording.2024-02-17.at.21.46.00.mov

What alternative solutions did you explore? (Optional)

@melvin-bot melvin-bot bot added the Overdue label Feb 19, 2024
@situchan
Copy link
Contributor

Thanks for the proposals everyone.
@brandonhenry the root cause is not correct
@wildan-m you considered only 1 issue in RCA while 3 issues total
@suneox your proposal is almost close but I'm not sure it's the right place to trigger signout manually.

@melvin-bot melvin-bot bot removed the Overdue label Feb 19, 2024
@wildan-m
Copy link
Contributor

@situchan my proposal updated with result video. I feel the result cover all of three cases.

@melvin-bot melvin-bot bot added the Overdue label Feb 21, 2024
@situchan
Copy link
Contributor

@wildan-m the root cause is still not updated

@melvin-bot melvin-bot bot removed the Overdue label Feb 21, 2024
@wildan-m
Copy link
Contributor

@situchan My Proposal updated.

It provides further clarification on the underlying issue, enhanced resolution, and the rationale behind avoiding calling signOut on the secondary device.

Copy link

melvin-bot bot commented Feb 22, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@jliexpensify
Copy link
Contributor

Waiting on @situchan to re-review

@melvin-bot melvin-bot bot added the Overdue label Feb 26, 2024
Copy link

melvin-bot bot commented Feb 26, 2024

@jliexpensify, @situchan Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@situchan
Copy link
Contributor

reviewing updated proposal today

@melvin-bot melvin-bot bot removed the Overdue label Feb 26, 2024
@situchan
Copy link
Contributor

@wildan-m's proposal looks good to me.
🎀 👀 🎀 C+ reviewed

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Feb 29, 2024
@wildan-m
Copy link
Contributor

@situchan @chiragsalian the PR is ready.

@chiragsalian
Copy link
Contributor

When we close high traffic account, do we need to request HT account activation again when we log back in?

I'm not 100% sure but I'm pretty sure you would have to request it again once you reopen the account. But why are you testing with the HT account. Won't it be easier to test this issue with non HT accounts.

@situchan
Copy link
Contributor

Maybe they wanna check this off

  • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).

I think it's fine as this bug is not related to HT account

@wildan-m
Copy link
Contributor

wildan-m commented Mar 1, 2024

@chiragsalian thank you for the confirmation. I have used my HT account for testing, could you assist me in re-assigning it to the HT account?

wildevemail+1@gmail.com

@wildan-m
Copy link
Contributor

wildan-m commented Mar 1, 2024

@chiragsalian, please ignore my earlier request. This form is automated to assign tasks promptly.

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Mar 7, 2024
@melvin-bot melvin-bot bot changed the title [$500] Account - Account is not simultaneously signed out on secondary device when closing account [HOLD for payment 2024-03-14] [$500] Account - Account is not simultaneously signed out on secondary device when closing account Mar 7, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Mar 7, 2024
Copy link

melvin-bot bot commented Mar 7, 2024

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

Copy link

melvin-bot bot commented Mar 7, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.48-0 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-03-14. 🎊

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

Copy link

melvin-bot bot commented Mar 7, 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:

  • [@situchan] The PR that introduced the bug has been identified. Link to the PR:
  • [@situchan] 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:
  • [@situchan] 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:
  • [@situchan] Determine if we should create a regression test for this bug.
  • [@situchan] 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:

@melvin-bot melvin-bot bot added Daily KSv2 Overdue and removed Weekly KSv2 labels Mar 14, 2024
@wildan-m
Copy link
Contributor

@jliexpensify @chiragsalian @situchan seems no regression here?

@melvin-bot melvin-bot bot removed the Overdue label Mar 14, 2024
@jliexpensify
Copy link
Contributor

Hi @wildan-m correct, I'll be paying now (no need to tag us!)

Bump @situchan to complete the checklist.

@jliexpensify
Copy link
Contributor

Payment Summary

Upwork job

@jliexpensify
Copy link
Contributor

Paid and job closed, waiting on checklist form Situ.

@jliexpensify jliexpensify removed the Awaiting Payment Auto-added when associated PR is deployed to production label Mar 15, 2024
@jliexpensify jliexpensify changed the title [HOLD for payment 2024-03-14] [$500] Account - Account is not simultaneously signed out on secondary device when closing account [PAID, WAITING ON SITU FOR CHECKLIST] [$500] Account - Account is not simultaneously signed out on secondary device when closing account Mar 15, 2024
@situchan situchan mentioned this issue Mar 15, 2024
50 tasks
@situchan
Copy link
Contributor

Offending PR with comment: https://github.com/Expensify/App/pull/31055/files#r1525621084
As this was caught by QA team, we can skip regression test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

7 participants