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 2023-10-02] [$500] IOS - Push notification is sent to the device even though the app is logged out. #26247

Closed
1 of 6 tasks
kbecciv opened this issue Aug 29, 2023 · 24 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production 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

@kbecciv
Copy link

kbecciv commented Aug 29, 2023

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


Action Performed:

  1. Log in to Account A.
  2. Turn OFF the network connection to enter OFFLINE mode.
  3. LOG OUT
  4. While the app is still in OFFLINE mode, send a message from another account to Account A (IMPORTANT STEP).
  5. Turn ON the network connection.
  6. Observer: Push notification appears.

Expected Result:

Push notification should not be sent if app is logged out

Actual Result:

Push notification is sent to the device even though the app is logged out.

Workaround:

Unknown

Platforms:

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

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.58.0 (tested on 1.3.62-3)
Reproducible in staging?: Yes
Reproducible in production?: n/a
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation

Push-notification-issue.1.MP4

Expensify/Expensify Issue URL:
Issue reported by: @tranvantoan-qn
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1692691382974179

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0134d9932ee5c7e512
  • Upwork Job ID: 1698485880458186752
  • Last Price Increase: 2023-09-03
  • Automatic offers:
    • hungvu193 | Contributor | 26547257
    • tranvantoan-qn | Reporter | 26547259
@kbecciv kbecciv added Daily KSv2 Needs Reproduction Reproducible steps needed Bug Something is broken. Auto assigns a BugZero manager. labels Aug 29, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 29, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Aug 29, 2023

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

@tranvantoan-qn
Copy link

tranvantoan-qn commented Aug 29, 2023

My Test/Reproduction note, hope it helps:

  • Make sure that we allowed the app to recieve Notification by turning Notification permission ON (permission popup will be displayed after installing and openning app first time)
  • The step 4: send a message from another account to Account A while the app is in OFFLINE mode - is a crucial step
  • To make sure Push Notification will be sent properly via Firebase, please check Production build

@hungvu193
Copy link
Contributor

hungvu193 commented Aug 30, 2023

Proposal

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

IOS - Push notification is sent to the device even though the app is logged out.

What is the root cause of that problem?

Let take a look at the signOut function:

function signOut() {
Log.info('Flushing logs before signing out', true, {}, true);
API.write('LogOut', {
// Send current authToken because we will immediately clear it once triggering this command
authToken: NetworkStore.getAuthToken(),
partnerUserID: lodashGet(credentials, 'autoGeneratedLogin', ''),
partnerName: CONFIG.EXPENSIFY.PARTNER_NAME,
partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD,
shouldRetry: false,
});
clearCache().then(() => {
Log.info('Cleared all chache data', true, {}, true);
});
Timing.clearData();
}

When user signed out offline, the API request will be pushed to the queue and wait for internet connection, after online again this api will be trigged and logged user out (including the token for push notification), in the mean time while signOut was calling if another user sent a message and user still can receive it because user was still logging out. This is the RCA. That why if you turned on the internet connection for a while and sent another message, you wouldn't receive the notification.

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

I think the most simple way to resolve this issue is adding more condition to our shouldShowPushNotification function.

// call this when signout
shouldShowPushNotification {
 if (!isAuthenticated) {return false}
}

What alternative solutions did you explore? (Optional)

Add the following line to our PushNotification.deregister (index.native.js) function:

     Airship.push.setUserNotificationsEnabled(false);
    Airship.push.iOS.setForegroundPresentationOptionsCallback(() => Promise.resolve([]));
    Airship.push.android.setForegroundDisplayPredicate((pushPayload) => Promise.resolve(() => false));

@melvin-bot melvin-bot bot added the Overdue label Sep 1, 2023
@sophiepintoraetz
Copy link
Contributor

Will test on Monday!

@melvin-bot melvin-bot bot removed the Overdue label Sep 2, 2023
@sophiepintoraetz sophiepintoraetz added External Added to denote the issue can be worked on by a contributor and removed Needs Reproduction Reproducible steps needed labels Sep 3, 2023
@melvin-bot melvin-bot bot changed the title IOS - Push notification is sent to the device even though the app is logged out. [$500] IOS - Push notification is sent to the device even though the app is logged out. Sep 3, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 3, 2023

Job added to Upwork: https://www.upwork.com/jobs/~0134d9932ee5c7e512

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Sep 3, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 3, 2023

Current assignee @sophiepintoraetz is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented Sep 3, 2023

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

@sophiepintoraetz
Copy link
Contributor

I'm able to reproduce this:

RPReplay_Final1693785333.MOV

@thesahindia
Copy link
Member

@hungvu193's proposal looks good to me!

🎀 👀 🎀 C+ reviewed

@melvin-bot
Copy link

melvin-bot bot commented Sep 5, 2023

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

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Sep 7, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 7, 2023

📣 @thesahindia Please request via NewDot manual requests for the Reviewer role ($500)

@melvin-bot
Copy link

melvin-bot bot commented Sep 7, 2023

📣 @hungvu193 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@melvin-bot
Copy link

melvin-bot bot commented Sep 7, 2023

📣 @tranvantoan-qn 🎉 An offer has been automatically sent to your Upwork account for the Reporter role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

@melvin-bot melvin-bot bot added the Reviewing Has a PR in review label Sep 8, 2023
@melvin-bot melvin-bot bot added Weekly KSv2 and removed Daily KSv2 labels Sep 8, 2023
@hungvu193
Copy link
Contributor

Waiting for final review from @roryabraham

@roryabraham
Copy link
Contributor

I'm actually really confused by the RCA here... it seems like we're missing something:

  • When the user signs out, we actually call Session.signOutAndRedirectToSignIn.
  • redirectToSignIn clears persisted requests. So when does the LogOut API call factually happen? Does it actually happen at all?
  • When we clear storage and redirect to sign-in (still offline), we should be triggering PushNotification.deregister – in fact that's the function you're leveraging in your PR. Why is Airship.removeAllListeners insufficient to prevent the notifications from being received?

@hungvu193
Copy link
Contributor

hungvu193 commented Sep 19, 2023

I'm actually really confused by the RCA here... it seems like we're missing something:

  • When we clear storage and redirect to sign-in (still offline), we should be triggering PushNotification.deregister – in fact that's the function you're leveraging in your PR. Why is Airship.removeAllListeners insufficient to prevent the notifications from being received?

I realized that PushNotification.deregister didn't clear all the EventType.PushReceived, when we first opened app or reload it, we called init 2 times. Here's the log I saw on Flipper.
Screen Shot 2023-09-19 at 10 46 38

So we will still receive the notification in the meantime api was calling.

  • When the user signs out, we actually call Session.signOutAndRedirectToSignIn.
  • redirectToSignIn clears persisted requests. So when does the LogOut API call factually happen? Does it actually happen at all?

When I checked the logs, I saw that we will call Logout after we reconnected to the network, that's also little weird to me because we already clear all the persisted request.
Screen Shot 2023-09-19 at 11 06 34

Overall, the current solution is just to disable the notification when user is logged out. Another solution can be creating a variable inside PushNotification/index.native.js to check if we already init the notification, once it's init we shouldn't call init again. How do you think?

@melvin-bot
Copy link

melvin-bot bot commented Sep 20, 2023

Based on my calculations, the pull request did not get merged within 3 working days of assignment. Please, check out my computations here:

  • when @hungvu193 got assigned: 2023-09-07 15:06:35 Z
  • when the PR got merged: 2023-09-20 13:24:38 UTC
  • days elapsed: 8

On to the next one 🚀

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Sep 25, 2023
@melvin-bot melvin-bot bot changed the title [$500] IOS - Push notification is sent to the device even though the app is logged out. [HOLD for payment 2023-10-02] [$500] IOS - Push notification is sent to the device even though the app is logged out. Sep 25, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Sep 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.73-1 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 2023-10-02. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

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

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

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:

  • [@thesahindia] The PR that introduced the bug has been identified. Link to the PR:
  • [@thesahindia] 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:
  • [@thesahindia] 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:
  • [@thesahindia] Determine if we should create a regression test for this bug.
  • [@thesahindia] 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.
  • [@sophiepintoraetz] 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 and removed Weekly KSv2 labels Oct 1, 2023
@sophiepintoraetz
Copy link
Contributor

@thesahindia, please request $500 once you have completed the checklist.

@thesahindia
Copy link
Member

It was an improvement. Not a regression. We just need to add a test case.

Steps:-

  1. Log in to account A.
  2. Turn Off the network connection to enter offline mode.
  3. Log out
  4. While the app is still in offline mode, send a message from another account to Account A
  5. Turn on the network connection.
  6. Verify that notification doesn't appear

@JmillsExpensify
Copy link

$500 payment approved for @thesahindia based on this comment.

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 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

8 participants