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

Duplicate desktop notifications for same chat. #474

Closed
mallenexpensify opened this issue Sep 11, 2020 · 17 comments
Closed

Duplicate desktop notifications for same chat. #474

mallenexpensify opened this issue Sep 11, 2020 · 17 comments
Assignees

Comments

@mallenexpensify
Copy link
Contributor

@garrettmknight has only Chat open on Desktop and is getting multiple notifications.
It could be related to this (https://github.com/Expensify/Expensify/issues/137041), but my hunch is no.
Also.. I'm not sure if it's directly related to this (#331), because this issue appears to be more about web and e.com vs chat.e.com.

cc @marcaaron and @chiragsalian since I think you've both worked on this

image

image

@ryanldonato
Copy link
Contributor

ryanldonato commented Sep 11, 2020

I'm experiencing the same issue
image

@twisterdotcom
Copy link
Contributor

+1, this is back today for me.

@mallenexpensify
Copy link
Contributor Author

mallenexpensify commented Sep 14, 2020

@marcaaron or @Jag96, can you look into this? It looks like dupe issues was fixed in the below that it looks like you two worked on. #333 and #357
I rarely get them but got a dupe this morn on Desktop
image

@marcaaron
Copy link
Contributor

I think @tgolen is working on fixing this already where we are reimplementing the active client manager #469

@mallenexpensify
Copy link
Contributor Author

@ryanldonato, when Chirag's update goes through it'll fix your issue because you're on web and the notifications that are coming from expensify.com will stop and you'll only get them via chat.expensify.com

@AndrewGable
Copy link
Contributor

FYI - I get 10x dupes per chat now

Screen Shot 2020-09-16 at 2 59 01 PM

@tgolen
Copy link
Contributor

tgolen commented Sep 16, 2020

Can you add a screenshot of the JS console (in verbose logging mode) and filter it for [NOTIFICATION]? I'd be interested to see what that looks like.

@AndrewGable
Copy link
Contributor

Screen Shot 2020-09-16 at 4 01 48 PM

@twisterdotcom
Copy link
Contributor

I got nothing for that:
image

@tgolen
Copy link
Contributor

tgolen commented Sep 18, 2020

I looked into this a little more this morning with the help of Ted, and here is what I've been able to determine so far.

  1. From looking at the server logs, the pusher event is only getting sent once
  2. The pusher client on the website ends up having multiple handlers subscribed to the same report comment event
  3. I think this is happening because of this line of code which will call resolve() every time the socket is connected (this happens every time pusher reconnects to the network).
  4. Each time resolve() is called then subscribeToReportCommentEvents() is also called, which is what is adding the multiple handlers

This is my theory anyway. I've been attempting to reproduce it locally without any luck. cc @marc

@tgolen
Copy link
Contributor

tgolen commented Sep 18, 2020

I could be wrong about that because this SO suggests that multiple calls to resolve() won't do anything, and it looks like I can confirm that.

image

So I don't know how we are subscribing to the same event multiple times, but I saw that it only happened after pusher had reconnected...

@marcaaron
Copy link
Contributor

Here's where we do the work of subscribing and will only subscribe if we are not already subscribed so my first guess would be that Pusher has unsubscribed from the channel - but maybe has not cleared out it's callback map so new callbacks can be added...?

https://github.com/Expensify/ReactNativeChat/blob/8fe5d09579a85f5b59af9e609144df452927d523/src/lib/actions/Report.js#L221-L230

It gets called from here:
https://github.com/Expensify/ReactNativeChat/blob/8fe5d09579a85f5b59af9e609144df452927d523/src/page/home/HomePage.js#L38

So maybe the HomePage component is re-mounting causing multiple event callbacks? Possibly during a redirect of some kind?

@marcaaron marcaaron self-assigned this Sep 18, 2020
@marcaaron
Copy link
Contributor

Either way, one idea is to treat these events like any other event we only want to attach one single callback to and make use of unbind just like we do in jQuery with off().on() see Pusher JS lib doc section on this here.

@marcaaron
Copy link
Contributor

Hmm so that didn't work. I think this is a possible bug with the Pusher library itself. Calling socket.disconnect() and socket.connect() results in multiple event callbacks. Tested this out by calling Pusher.reconnect() method multiple times which is just doing this...

https://github.com/Expensify/ReactNativeChat/blob/13f818ba65ddbfb2b5fcd33945c8063877f9fe8f/src/lib/Pusher/pusher.js#L357-L363

And each time a new callback was added. Not really at all what I would suspect so will keep digging here and possibly open an issue with Pusher about it.

@marcaaron
Copy link
Contributor

Ok got it. Not a Pusher bug. Expensify 🐛

@marcaaron
Copy link
Contributor

Tested the theory above again but this time subscribed with a new event directly to a channel and did not observe the same behavior. Then figured it must be something we are doing and it was. We were binding the subscription_succeeded event which would re-fire when calling connect thus binding another event to the channel here:

https://github.com/Expensify/ReactNativeChat/blob/0c949268e8c696e90f350b2e0eb64fca7ff8c20a/src/lib/Pusher/pusher.js#L191-L192

@tgolen
Copy link
Contributor

tgolen commented Sep 21, 2020

Aha! Great sleuthing, Marc!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants