firebase / quickstart-android

Firebase Quickstart Samples for Android
https://firebase.google.com
Apache License 2.0
8.78k stars 7.32k forks source link

service unstable - messages received after huge delay or not at all #83

Closed or-dvir closed 7 years ago

or-dvir commented 8 years ago

Step 2: Describe your environment

first device:

second device:

im trying to test the FCM capabilities using the messaging sample, however messages send via FCM console are highly unstable/unpredictable. sometimes messages are received within a few seconds, sometimes after a few minutes (could even be over 10 and even 20 minutes!), and sometimes not at all... this is happening randomly - for example, a message could be received immediately, and a message sent right after it will only be received after 10 minutes.

i have set the priority of the messages to high, and time-to-live to maximum to make sure the messages are not discarded.

Steps to reproduce:

  1. add sample project to a new or existing FCM project
  2. try send messages through FCM messaging console

    Observed Results:

random behavior. messages are received with huge delay or not at all

Expected Results:

messages received immediately, or within less than 5 seconds.

Relevant Code:

none. sample "messaging" app

kroikie commented 8 years ago

Hi @or-dvir how reproducible is this behaviour? Out of say 10 messages how many would you say are massively delayed or not delivered at all? This will help me reproduce.

or-dvir commented 8 years ago

@kroikie thank you for your response. unfortunately its really hard to say as it comes and goes in waves... i mean there could be a time where 10/10 messages would be received within a few seconds, a time where a few messages in a row would go through, but any message sent right after those would not be received, and even a time where 0/10 messages would re received, and after X minutes (could be even 10 or 20) i would suddenly receive all 10 messages at once one after the other. also, im seeing different behavior from the 2 devices mentioned - it seems to happen more often on the assus zenpad, where as performance on the LG G3 is noticeably better but still there could be times where very few messages will be received, if any at all.

i can only guess that the line of messages is getting stuck or blocked for some reason at certain times, and once that blockage has been removed everything is working fine again.

kroikie commented 7 years ago

Is your app in the foreground or background when you are testing this?

or-dvir commented 7 years ago

@kroikie both

kroikie commented 7 years ago

This will be difficult to troubleshoot without some more information. Notifications sent from Firebase console behave differently depending on whether the app is in the foreground or background.

If your app is in the foreground then you will only see the notification represented as a log message in logcat. If your app is in the background then you will see the notification showing up in the notification area.

To make things a bit clearer could you try foreground and background separately and see if you are seeing the same inconsistencies? If you have already done this are you seeing any error messages in the logcat that would indicate that something is wrong?

or-dvir commented 7 years ago

@kroikie

This will be difficult to troubleshoot without some more information. Notifications sent from Firebase console behave differently depending on whether the app is in the foreground or background.

If your app is in the foreground then you will only see the notification represented as a log message in logcat. If your app is in the background then you will see the notification showing up in the notification area.

To make things a bit clearer could you try foreground and background separately and see if you are seeing the same inconsistencies? If you have already done this are you seeing any error messages in the logcat that would indicate that something is wrong?

i understand this is not easy to troubleshoot... but unfortunately this is all the information there is (unless you ask for something specific). imagine this from my side - also all i am doing is basically extending the firebase service which does everything for me. while this may be great and saving me a lot of work, it gives me zero control when it comes to debugging.

i am ware of the foreground-background thing and i am definitely doing it correctly because there are times where messages do arrive. foreground messages seem to work better than background, but not by much. the LG G3 seems to work better than the asus zenpad, but it's definitely also happening on the LG. also if the app is completely closed (as in swiped away from the recent apps/task menu) it seems to be worse.

personally i didnt see anything in the log cat, but could be that i simply misunderstand the firebase messages. i see a lot of messages about "firebase crash" or something like that but to me it looks like these are related to the fire base crash report feature, and do not mean that firebase actually crashed.

kroikie commented 7 years ago

Thanks for helping to investigate this, could you try one more thing, could you try an emulator with google APIs and see if you are getting the same issues. I am thinking that there could be issues with how these devices are implementing app closures which could affect whether or not the messages are delivered to the devices when they are in the background. The foreground issue is really strange but if you can check the issue on an emulator that would help.

or-dvir commented 7 years ago

i tried working with the emulators in the past and they are pretty much impossible to work with. they take 30+ minutes just to turn on

kroikie commented 7 years ago

I know what you mean, however we have updated the emulators recently and they are much more responsive. I would recommend giving them a try, what I'm trying to establish is whether or not it is the device or the sample or FCM. Trying it on an emulator (with Google APIs) would help eliminate the device being the issue.

or-dvir commented 7 years ago

like i said, i already tried on 2 different devices

or-dvir commented 7 years ago

@kroikie when trying to clone a virtual device (any virtual device) i get this exception:

null java.lang.NullPointerException at com.android.tools.swing.util.FormScalingUtil.scaleComponent(FormScalingUtil.java:183) at com.android.tools.swing.util.FormScalingUtil.scaleComponentTreeWorker(FormScalingUtil.java:140) at com.android.tools.swing.util.FormScalingUtil.scaleComponentTree(FormScalingUtil.java:111) at com.android.tools.swing.util.FormScalingUtil.scaleComponentTree(FormScalingUtil.java:98) at com.android.tools.idea.avdmanager.ConfigureDeviceOptionsStep.(ConfigureDeviceOptionsStep.java:97) at com.android.tools.idea.avdmanager.CloneDeviceAction.actionPerformed(CloneDeviceAction.java:46) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6535) at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) at java.awt.Component.processEvent(Component.java:6300) at java.awt.Container.processEvent(Container.java:2236) at java.awt.Component.dispatchEventImpl(Component.java:4891) at java.awt.Container.dispatchEventImpl(Container.java:2294) at java.awt.Component.dispatchEvent(Component.java:4713) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466) at java.awt.Container.dispatchEventImpl(Container.java:2280) at java.awt.Window.dispatchEventImpl(Window.java:2750) at java.awt.Component.dispatchEvent(Component.java:4713) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at java.awt.EventQueue$4.run(EventQueue.java:731) at java.awt.EventQueue$4.run(EventQueue.java:729) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:866) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:650) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:381) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:109) at java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:184) at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:229) at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:227) at java.security.AccessController.doPrivileged(Native Method) at java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:227) at java.awt.Dialog.show(Dialog.java:1084) at com.intellij.openapi.ui.impl.DialogWrapperPeerImpl$MyDialog.show(DialogWrapperPeerImpl.java:792) at com.intellij.openapi.ui.impl.DialogWrapperPeerImpl.show(DialogWrapperPeerImpl.java:465) at com.intellij.openapi.ui.DialogWrapper.invokeShow(DialogWrapper.java:1638) at com.intellij.openapi.ui.DialogWrapper.show(DialogWrapper.java:1587) at com.intellij.openapi.ui.DialogWrapper.showAndGet(DialogWrapper.java:1602) at com.android.tools.idea.wizard.dynamic.DynamicWizard.showAndGet(DynamicWizard.java:531) at com.android.tools.idea.avdmanager.CreateAvdAction.actionPerformed(CreateAvdAction.java:41) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6535) at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) at java.awt.Component.processEvent(Component.java:6300) at java.awt.Container.processEvent(Container.java:2236) at java.awt.Component.dispatchEventImpl(Component.java:4891) at java.awt.Container.dispatchEventImpl(Container.java:2294) at java.awt.Component.dispatchEvent(Component.java:4713) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466) at java.awt.Container.dispatchEventImpl(Container.java:2280) at java.awt.Window.dispatchEventImpl(Window.java:2750) at java.awt.Component.dispatchEvent(Component.java:4713) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) at java.awt.EventQueue$4.run(EventQueue.java:731) at java.awt.EventQueue$4.run(EventQueue.java:729) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:866) at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:650) at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:381) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

kroikie commented 7 years ago

Hi @or-dvir I'm not sure that we can trouble shoot this any further without more info. So I'll close this issue but feel free to create a new one if you can provide a bit more detail. There are many reasons that could cause delay in messages, eg: network conditions, if the app is forced stopped.

rackaam commented 7 years ago

Hi

I have the exact same problem with my app. The reception was instantaneous 3 days ago, today I receive a message either with a 10 minutes delay (approximately) or not at all. I haven't change of devices or networks.

The messages sent from the Firebase web UI are never delivered.

As @or-dvir, I don't have a lot of informations to debug this. Topic subscription works fine, and I dont't have any error message from Firebase.

aznxfrost commented 7 years ago

Just want to say i'm also experiencing this issue on my android firebase implementation.

Sometimes messages are simply not being received, and after X minutes all of a sudden all of them comes through. (Though the device is connected to WIFI and has perfectly stable internet connections).

Its irrelevant whether the app is in foreground or background.

insightfulfellow commented 7 years ago

This is most definitely still a pretty critical issue with Firebase / GCM that needs to be properly addressed. It's kind of disappointing that so many people are complaining about this same exact issue on the internet and reviewers evade and dodge the problem altogether....

lveneziano commented 7 years ago

Hi Mathias, please would like send me your Github APP project name?

Thank´s , see ya.

2016-09-01 17:03 GMT-03:00 aznxfrost notifications@github.com:

Just want to say i'm also experiencing this issue on my android firebase implementation.

Sometimes messages are simply not being received, and after X minutes all of a sudden all of them comes through. (Though the device is connected to WIFI and has perfectly stable internet connections).

Its irrelevant whether the app is in foreground or background.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/firebase/quickstart-android/issues/83#issuecomment-244195287, or mute the thread https://github.com/notifications/unsubscribe-auth/AGMwKpRb73A96ID7V5roiHlbY-zc9hexks5qly-YgaJpZM4JMJ2e .

sakthikanth commented 7 years ago

how whatsapp receive messages through this ?

SoerenBusse commented 7 years ago

I've the same problem. Sometimes it's working pretty fast, but other times the notification never delivered to the devices. No notification from the firebase console or from my PHP script are working.

Is there some spam protection that prevents to send to much messages to the devices?

luktar commented 7 years ago

The same problem. Tested on 3 devices and 2 emulators by wifi and GSM. Delay and randomly received messages.

Tjong commented 7 years ago

Same here and also tested on now 3 different devices. Sometimes it's working flawless with instant response and sometimes the messages are not received at all. Then waiting for like 10 minutes → Suddenly everything is working fine and then after a few builds in Android Studio and only minutes later it's again completely unresponsive. That randomness makes it really hard to debug and is also very frustrating if you can't figure out why that's happening, but at least it seems like I'm not the only one.

luktar commented 7 years ago

I had this problem because I thought that all messages with notification and data fields filled will be received by play services and displayed on notification bar if application is backgrounded or killed.

But it is not working this way!

Event if application was killed (swiped out) or application is in background mode and device is in sleep mode notifications are received all the time but once in notification bar and another time in method public void onMessageReceived(RemoteMessage remoteMessage) inside application - it is random.

My test was based on playing sounds when push notification was received - I didn't hear a sound in onMessageReceived method because I didn't implement it at all.

Now my application receives 100% messages from two sources - notification bar and by handling onMessageReceived method.

It's good tutorial about how to start with firebase messaging. Works as expected.

Tjong commented 7 years ago

Well, but my messages are always data-only (So without notifications). So they should be received at any time, or am I wrong?

luktar commented 7 years ago

Well, but my messages are always data-only (So without notifications). So they should be received at any time, or am I wrong?

They should be received only when your application is able to receive them - hasn't been released by system (ex. not enough ram space).

Check this out: https://firebase.google.com/docs/cloud-messaging/android/receive#handling_messages

I think the best solution is to have both message types - data and notification.

When your app has been stopped by system, google play service will receive notification and show it in notification bar. When user click on this notification, your application can start activity specified by you in "click_action" notification field. Also play services can play music and show image stored in your "*.apk" file on device. Data sent in notification are passed by extras field of newly created activity.

When your app is able to receive messages (hasn't been stopped by system) by method onMessageReceived you can get data from your message (all including natofication) open specified by you activity and update it.

Good luck.

ksachdeva11 commented 7 years ago

Facing the same issue.. Can someone please advice how to fix this ? Thanks!

souravde commented 7 years ago

Facing the same issue from past couple of days while sending notifications via Firebase Topic. Please help..

AymanElKhamkhami commented 7 years ago

I encountered the same issue today, the notifications have been received immediately on Android since I first implemented the project, but today they were delayed for almost half an hour, and suddenly I received a burst of all pending notifications all at once. I faced this problem in both cases when the app is in foreground and background.

FedeDP commented 7 years ago

Same issue here... In my case, it seems that switching connectivity source (wifi -> 3g, or 3g -> wifi) "unlocks" fcm. Is this the case for you too?

luktar commented 7 years ago

Hello FedeDP. I have no more problems with FCM - it doesn't metter if device is connected by 3G or WIFI. Check out my posts above - it may help you.

AymanElKhamkhami commented 7 years ago

FedeDP, my problem wasn't related to connectivity, It was encountered when the messages were sent to topics instead of specific devices.

FedeDP commented 7 years ago

Yes, by "you" i was referring to "you all"! By the way, the issue here is that messaging "backend -> app" stops working (even with opened app) until i switch connectivity source or well, waiting for long time also fixes the problem. I can see my backend that sends messages to my device, but device does not receive them. And, as soon as device finally receives them, it receives a burst of all of the previous messages.

LutfiTekin commented 7 years ago

I have the same isssue. When i try with tokens it is working but topics are not reliable, sometimes good sometimes not.

Salmondx commented 7 years ago

Same issue for me. Sometimes it works perfectly, instantly delivers all of my messages and sometimes delay time is awful - 20-30 minutes and burst of messages simultaneously after this period.

jluis859 commented 7 years ago

Same issue here on Android, I have tested with wifi, the delay time is huge.

It only works if you toggle the wifi, after that it receives all messages.

adriancoman commented 7 years ago

Same issue here. Tested on multiple devices, multiple network states (wifi, 4g).

I just implemented the SDK as per documentation, not receiving any push notification (sent 10+) and then all of a sudden I got them all in the MESSAGING_EVENT Service. After that all was working good.

Today, same thing happened again.

ForGuru commented 7 years ago

I found unreliable and unstable Firebase messages as it was in Google Cloud Messaging. Some time I received when I change network (WiFI to Data or Data to WiFi) or sometime it doesnt work on a specific WiFi.

I think this is the issue due to Implementation of TCP stack in android which looses connection with Google / Firebase Server

Dimitar-Karazhov commented 7 years ago

Facing the same issue.. How to fix this ?

maadrimosharef commented 7 years ago

Same Issue Here!!

dwarrier commented 7 years ago

For me, there are times where the service works perfectly (messages are received on the target devices), but at other times no messages are received on the device. In these cases I still get successful responses to requests to the FCM service. I don't feel like it's a throttling issue since currently I'm sending <10 messages a minute to one device.

pajatopmr commented 7 years ago

Our team just implemented app-invites and it appeared to be working nicely. Now, only a day or two later, we started experiencing the delays and dropped messages that others have documented in this issue. If we have implemented this feature incorrectly, we sure have a lot of company. But to me, it would appear to be a systemic Firebase or Google issue. So I do not understand why the issue has been closed. Worse, as it stands today with this sporadic success behavior, the recommended Firebase/Android solution to app invites is a non-starter. Fwiw, the character of the issue as we see it is that the code reports that invite mail has been sent, but in fact, the message has not been sent. For messages that do actually get received there is a corresponding sent message in the senders "Sent" mail folder. For messages that are delayed or dropped there is no corresponding message in the "Sent" mail folder even though Toast messages and log entries indicate otherwise.

Narender8 commented 7 years ago

I am also facing this issue. sometime message not arrive for a long time and after that, when it becomes bulk of messages (like 7,8 messages) then they all arrive suddenly. This is the severe issue i am facing. Please go through it or suggest me some other notification tool which is working well in marking except parse notification as it is already shutdown.

rrrooommmaaa commented 7 years ago

I have this problem in Android 7.0 Xamarin project and was able to get stable results. My service sends a collapsible message to a topic each minute and for several hours I receive each message on time on an GAPI emulator, but then I start to receive one message per three minutes (each third message). After I wipe the emulator device, it receives normally for several hours and then again, each third message. Probably a bug in Android messaging or something (or anti-throttle measures). Easily reproducible. Just need to find a right google guy to address to. BTW, when I run two devices subscribed to the same topic, one of them can receive messages normally, and the other can receive each third message, so looks like this is a client-side issue.