Skip to content

[HOLD for payment 2024-07-10] Buildup of unused Pusher subscriptions #43089

Closed

Description

@roryabraham

Coming from #42447 (comment)...

Bug

Opening a workspace chat via the header in an IOU report doesn't unsubscribe from the IOU report's channel. These subscriptions then build up over time, so you can end up with a ton of AuthenticatePusher calls!

Actions taken

  1. After opening 4 different reports, open an IOU report
  2. Tap on the workspace name in the header

Expected result

you should see a log line that says the IOU report's pusher channel has been unsubscribed

Actual result

No such log line. The pusher channel subscription is maintained unnecessarily.

Issue OwnerCurrent Issue Owner: @
Issue OwnerCurrent Issue Owner: @muttmuure

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jun 5, 2024
  2. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jun 5, 2024
  3. melvin-bot commented on Jun 5, 2024

    @melvin-bot

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

  4. melvin-bot commented on Jun 5, 2024

    @melvin-bot

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

  5. dominictb commented on Jun 5, 2024

    @dominictb
    Contributor

    Proposal

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

    When tapping on the workspace name in the header. No such log line. The pusher channel subscription is maintained unnecessarily.

    What is the root cause of that problem?

    When we tap on the workspace name in the header, we can see the [Pusher] Unbinding event with eventName of client-userIsLeavingRoom. That means the isLeavingRoom event is cleaned up properly here.

    However, the client-userIsTyping event is not cleaned up well, so the channel subscription remains.

    The implementation to unsubscribe from client-userIsTyping is in

    Report.unsubscribeFromReportChannel(reportID);

    We can see that it only unsubscribe if the screen becomes unfocused. We're not unsubscribing when the screen unmounts, like we did with the client-userIsLeavingRoom in there.

    So in case the screen unmounted completely, the client-userIsTyping is not unsubscribed.

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

    Unsubscribe the client-userIsTyping when the screen is unmounted.

    We have the unsubscription logic here, we can put it in the clean up function of an useEffect

    useEffect(() => {
            return () => {
                if (didSubscribeToReportTypingEvents.current) {
                    didSubscribeToReportTypingEvents.current = false;
                    InteractionManager.runAfterInteractions(() => {
                        Report.unsubscribeFromReportChannel(reportID);
                    });
                }
            }
        }, []);
    

    In here we don't need to check for topmostReportId because in case of unmounting, of course the current report will no longer be shown to the user.

    Just to note this is the same pattern we used for unsubscribing from the userIsLeaving event

    interactionTask.cancel();
    if (!didSubscribeToReportLeavingEvents.current) {
    return;
    }
    Report.unsubscribeFromLeavingRoomReportChannel(report.reportID);
    .

    So after both events are unsubscribed correctly, the channel itself will be unsubscribed.

    The logic to unsubscribe userIsTyping is both used for unfocused and unmounted case, so it can be put in a method for DRY.

    What alternative solutions did you explore? (Optional)

    In

    Report.unsubscribeFromLeavingRoomReportChannel(report.reportID);
    , unsubscribe both events, or unsubscribe the entire channel by calling unsubscribe with empty event name.

    Also to note, we're subscribing and unsubscribing the userIsTyping and userIsLeaving in 2 different places, it's possible that we can combine them in 1 place, either the place of userIsTyping now or of the userIsTyping.

  6. jjcoffee commented on Jun 5, 2024

    @jjcoffee
    Contributor

    @dominictb's proposal LGTM! I like the idea of having both events unsubscribe in the same useEffect.

    🎀👀🎀 C+ reviewed

  7. melvin-bot commented on Jun 5, 2024

    @melvin-bot

    Current assignee @roryabraham is eligible for the choreEngineerContributorManagement assigner, not assigning anyone new.

  8. 25 remaining items

  9. melvin-bot commented on Jul 10, 2024

    @melvin-bot

    Payment Summary

    Upwork Job

    • ROLE: @jjcoffee paid $(AMOUNT) via Upwork (LINK)
    • ROLE: @dominictb paid $(AMOUNT) via Upwork (LINK)

    BugZero Checklist (@muttmuure)

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

    @roryabraham
    ContributorAuthor

    Thanks @jjcoffee. @muttmuure this is done - all that's left is to add the regression tests and pay this out

  11. melvin-bot commented on Jul 15, 2024

    @melvin-bot

    @jjcoffee, @muttmuure, @roryabraham, @dominictb Eep! 4 days overdue now. Issues have feelings too...

  12. mallenexpensify commented on Jul 16, 2024

    @mallenexpensify
    Contributor

    @dominictb @jjcoffee , can you please accept the job and reply here once you have?
    https://www.upwork.com/jobs/~01f0dc2c395e40f075

    Thanks for the Regression Test steps @jjcoffee

  13. dominictb commented on Jul 16, 2024

    @dominictb
    Contributor

    @mallenexpensify Done, thanks 🙏

  14. jjcoffee commented on Jul 17, 2024

    @jjcoffee
    Contributor

    @mallenexpensify Accepted, thanks!

  15. melvin-bot commented on Jul 17, 2024

    @melvin-bot

    @jjcoffee, @muttmuure, @roryabraham, @dominictb 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

  16. mallenexpensify commented on Jul 19, 2024

    @mallenexpensify
    Contributor

    Contributor: @dominictb paid $250 via Upwork
    Contributor+: @jjcoffee paid $250 via Upwork

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