chat-sdk-android icon indicating copy to clipboard operation
chat-sdk-android copied to clipboard

Chat message not received occasionally, after idling for a while

Open brucexia opened this issue 9 years ago • 20 comments

I noticed my message was not getting delivered/received this morning after leaving the sample apps idle for maybe half hour or so. Is this known issue? Could this be firebase issue? Not seeing it yet after restarting the app.

brucexia avatar Oct 31 '17 16:10 brucexia

Can you check to see if they are being added correctly to Firebase? This sounds like goOffline is being called and then goOnline isn't being called again. When you look at the Firebase data is the user shown as online i.e. user/online = true? It would be worth adding some logging into these two methods.

bensmiley avatar Oct 31 '17 18:10 bensmiley

@bensmiley so for user a and b, user a can receive message from b, but user b is not receiving from a. In the database, only user a is online. So it looks like the the currentUserOn is not being triggered after the app comes back

brucexia avatar Oct 31 '17 18:10 brucexia

The AppBackgroundMonitor.enabled = false, and FirebaseReferenceManager.references is empty. After restarting the app, the messages are still missing - Apparently this is due to the fact that the client was actually connected so Firebase is not pushing the missing messages.

brucexia avatar Oct 31 '17 21:10 brucexia

I have the same issue, it's with the old version, #140, but I tested again with the new version, from the firebase api, firebase auto disconnect after 60 seconds of iding, but the goOnline method sometimes doesn't get the user connected back to firebase.

Allansk2 avatar Nov 01 '17 03:11 Allansk2

@Allansk2 that's different. In my case the problem isnt with firebase connection - it's still connected but somehow all event listeners are removed and the user online status is not set.

brucexia avatar Nov 01 '17 05:11 brucexia

@bensmiley any suggestion how this could be fixed? I think AppBackgroundMonitor is the problem but I don't see obviously where it could go wrong. I understand Firebase SDK manages connection automatically, what's the impact if we disable AppbackGroundMonitor?

brucexia avatar Nov 01 '17 15:11 brucexia

From what you've said, it looks like logout has been called. Calling log out will generally disable the background monitor and remove the firebase references. It should also start the Login activity.

The purpose of the background monitor is to set the user offline if the app is closed for more than a set period of time. It won't remove any listeners.

I've not seen this issue so far in testing and I can't seem to replicate it. Have you made any changes to the project? Can you replicate this with the default unmodified version from Github?

Could you checkout the default version of the product and try to find a sequence of steps that I can use to reproduce the issue?

bensmiley avatar Nov 02 '17 09:11 bensmiley

@bensmiley I'm facing similar issue now - randomly chat stop receive messages from server, however, messages I send from the same chat appear in firebase. If I restart chat, I'll continue not receive messages from server. The user stays online during being in chat, as I can see in firebase, and also authenticated. Also, other activity subscribes for event MessageAdded and it's also doesn't receive event if chat doesnt (but if chat works well, then other activity also receives events).

Let me explain how we use ChatSDK - may be this will clear up the situation. The library was integrated inside app which already has a firebase. We used only core, firebase_adapter and ui modules. ChatSDK configured in Application onCreate(). When user login in app, it also login in chat with the same data. Later user can create private 1to1 chat with other user (using NM.thread().createThread(List) and pass threadId to that user. User opens Chat (InterfaceManager.shared().a.startChatActivityForID() ) and starts chatting. Any chance I missed something and therefore this problem occurs?

Yariko-chan avatar Nov 02 '17 13:11 Yariko-chan

The following may (or may not) be related: Issue #154, which is now closed, exhibited the same exact behavior after the crash (see my comment there). (@rohitbhoite : There was no fetching pop up showing). This is easily reproducible and may provide a hint as to what leads to this type of behavior. And yet again, it may be totally unrelated :) I hope this helps.

OferRnz avatar Nov 02 '17 18:11 OferRnz

@bensmiley No I reproduced it several times without logout. The only change I made to the sample app is the firebase credentials so I can see the data. Haven't seen it happening after commenting out the AppBackgroundMonitor calls

brucexia avatar Nov 02 '17 18:11 brucexia

In my case one of the problem was that I keep my users authorised until they explicitly click "Logout", so after app restart disposableList in FirebaseEventHandler is void and subscribing to source() and sourceOnMain() doesnt work. To solve the problem, I call FirebaseEventHandler.shared().currentUserOn(); after restart.

But also may be some other problem exist, because while debugging I noticed that disposableList contains objects, that already disposed. disposableList.dispose() clears list, so they may be disposed by some other reason, not by logging out or something else. I can't reproduce it know.

Hope this will help someone.

Yariko-chan avatar Nov 10 '17 13:11 Yariko-chan

@Yariko-chan When the app starts up, you should at least call NM.auth().authenticateWithCachedToken() this will do the necessary setup.

With regards to the disconnect issue, I'm adding a fix to the latest version. Hopefully it will help.

bensmiley avatar Nov 10 '17 15:11 bensmiley

@bensmiley thanks a lot! I forgot about this option)

Yariko-chan avatar Nov 10 '17 16:11 Yariko-chan

This issue should be fixed in the latest release. Please re-open the issue if it still persists.

bensmiley avatar Nov 13 '17 19:11 bensmiley

I'm facing the same issue with version 4.8.12. I had to clear app data and login back and then all messages started showing up again. Any thoughts on how to solve this issue?

Mahmoud-S-Ali avatar Jun 10 '20 16:06 Mahmoud-S-Ali

What is the problem you're facing?

bensmiley avatar Jun 10 '20 18:06 bensmiley

Suddenly messages stopped showing up on both sides (sender/recipient). They worked fine at start but all I remember I kept both devices idle for a while. I then removed app data from one device and logged in again, then messages appeared on that device only. I repeated the process with the other device and messages started showing on the other as well. It's most probable to happen again. Not sure what caused the issue in the first place but I'll try to reproduce it and let you know with the steps.

Mahmoud-S-Ali avatar Jun 10 '20 18:06 Mahmoud-S-Ali

@Mahmoud-S-Ali we've just released a bit update to the project. Depending on how many customizations you've made it may be worth updating.

https://github.com/chat-sdk/chat-sdk-android

I expect you will find this issue is fixed with the new version.

bensmiley avatar Jun 10 '20 18:06 bensmiley

That sounds great. I'll test it and let you know if the issue is reproduced.

Mahmoud-S-Ali avatar Jun 10 '20 19:06 Mahmoud-S-Ali

I haven't tried the latest version yet '5.0.0rc7', but I fixed the issue by calling: if (ChatSDK.auth().isAuthenticated()) { disposableList.add(ChatSDK.auth().authenticate() .subscribe(new Action() { @Override public void run() throws Exception { afterAuthentication(); } }, throwable -> logError(throwable.getMessage()))); }

at the start of my activity

Mahmoud-S-Ali avatar Jun 14 '20 10:06 Mahmoud-S-Ali