firebase / quickstart-android

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

Delay and non-delivery of messages with FCM on some networks #307

Closed sparklton closed 7 years ago

sparklton commented 7 years ago

I am observing a problem described in details here: https://github.com/firebase/quickstart-android/issues/83

It appears to be closed without any apparent reason or solution.

Looking into the syslog of my Nexus I am seeing that the connection between smartphone and FCM server gets reset after some inactivity period. This results in what was described in #83, and it was actually discussed quite vigorously here many years ago: https://productforums.google.com/forum/#!topic/nexus/fslYqYrULto

After all those years with the most recent Android software, I am stumbling on the same issue.
Does anyone know how to modify the keep-alive rate in Android so that using FCM would make any practical sense? I am particularly interested in how to make it work with Cordova based apps.

Ironically, I am having iOS devices here sitting along with the Androids - none of the iPhones misses a single message while Androids loose the connection to its own service provider every few minutes of idleness...

broakenmedia commented 7 years ago

I am experiencing the same issue, i'll be sending messages from my server to the device with no problem at all. I'll come back in 5 minutes and try sending another message but nothing is received for minutes->hours where it'll suddenly work again. No idea why it was closed and locked!

sparklton commented 7 years ago

I have spent substantial amount of time chasing this issue into the core and I found what is going on. At least on my network. This is not an FCM problem but an Android OS problem and the solution is yet to be found.

In order to keep a live socket with an idle connection, there must be some kind of keep alive message from a client. It is important on some networks to indicate that you are still active. Otherwise they just close the connection to save the resources. My silly home router does that for no apparent reason and I can't find a way to twitch this. Many cellular carries do this too. It really depend on the provider.

I looked into the syslogs of my telephone and found that Android keeps loosing the connection to FCM because its heart beat with the service is way to rare (15 minutes on Wifi network). By the time Android client wakes up to ping the server, the connection is long gone and only now it starts to re-connect. This results in many minutes of random sporadic behavior. Very frustrating. iOS on the other hand do the heart beat more often and never seem to loose the line. It's that simple.

There are more frustrated developers out there, it's being for quite some time: https://productforums.google.com/forum/#!topic/nexus/fslYqYrULto https://eladnava.com/google-cloud-messaging-extremely-unreliable/

And because Google don't want to fix this, the developers make stuff like this: https://play.google.com/store/apps/details?id=com.andqlimax.pushfixer https://play.google.com/store/apps/details?id=com.elotro.pushheartbeat

.. which work but it's not a solution.

samtstern commented 7 years ago

@sparklton thank you for the very detailed explanation. I am going to forward this on to the FCM team and see if they're aware/have a suggestion.

In the meantime I am going to close this issue since it's not really related to the code in this repository, but I will update the issue if anything interesting comes up.

samtstern commented 7 years ago

Hey all, apologies for the delayed response. I talked to the FCM team and learned a lot about this issue.

In the majority of cases these types of problems are caused by the network infrastructure. FCM uses a dynamic heartbeat so to simply reduce the heartbeat interval (like those apps do) would use much more battery for the average user and not make things much better in most cases.

If either of you can still reproduce this issue and feels comfortable sending a full Android bugreport to me (samstern@google.com) I can provide it to the FCM team for more investigation.

KethuY commented 6 years ago

I am also facing same problem.Some times push notifications are getting so fast.Some times its huge delay

Please help me how to fix it.

kroikie commented 6 years ago

@VyshuRaj Please file a support request with Firebase Support since it seems you are implementing FCM correctly on your end so more troubleshooting is necessary.

razam217 commented 6 years ago

Any fix for this problem?

kroikie commented 6 years ago

@razam217 FCM is currently operating normally. For status of FCM see the Firebase status dashboard. If you are having issues please file a support ticket.

ilyasdirin commented 5 years ago

I have the same problem, it delays message sometimes minutes. iOS devices do not face with this issue in the same network that my android devices in. So I do not think the problem is about network. iOS devices have no delay under same condition.

kroikie commented 5 years ago

@ilyasdirin what is the target of the messages you are seeing the delays with?

ilyasdirin commented 5 years ago

It targets only one device with high priority. The problem is that when I change network (from 4G to Wifi or vice verca) I am not able to get FCM about at least one minute. I'am sharing the request below. Is there any way to notify FCM when the connected network change?

POST /fcm/send HTTP/1.1 Host: fcm.googleapis.com Authorization: key=ServerKey Content-Type: application/json cache-control: no-cache Postman-Token: { "priority" : "high", "data": { "my_data": "123456", }, "to": "FirebaseToken" }

kroikie commented 5 years ago

@ilyasdirin That payload looks good to me. There is nothing on the API side that can help improve the speed of delivery. Please file a report at firebase.google.com/support identifying the network and devices that you are seeing the delay, maybe there is something that can be done on the FCM side to improve the delivery latency.

ghost commented 5 years ago

Same here. iOS has no delay. Android/FCM is not reliable.

Roeisteinberg commented 5 years ago

My team also observed this problem and some time the push isn't received into the client at all and no matter how many retries. Our project is VoIP so it's critical for us. Please help to solve this problem, if you need more logs or any others info please let me know.

YPareek commented 5 years ago

I am facing the same issue while sending web push notifications on desktop devices(in chrome). I understand that this could be an issue for mobile devices to save battery life, but why is it happening for desktop device?

tomerpetel commented 5 years ago

@Roeisteinberg any changes with FCM reliability? I'm considering relaying on FCM to VoIP app as well...

ilyasdirin commented 5 years ago

@tomerpetel no improvements has been done since I informed to FCM. I am still facing the same problem in my active projects. FCM side also does not pay serious attention to such an important problem.

tomerpetel commented 5 years ago

@ilyasdirin any other way to receive notifications in a reliable way? Can't use service as well since Oreo unless using startForegroundService... really frustrating.

ilyasdirin commented 5 years ago

@tomerpetel there are some paid push notification sdk's available which claims delayless notification but I haven't tried any of them so I can not offer you one.

habibqureshi commented 5 years ago

Android fcm is not reliable for android specially for VoIP application. we are also looking for another SDK's

tomerpetel commented 5 years ago

@habibqureshi I'd be happy if you'll share your other SDK pursuit results :) I'm working on a VoIP application and having the same issue.

tutorbear commented 4 years ago

Catapush is a great service , you can try it out

devakrishna33 commented 4 years ago

Facing same issue, is there a solution yet?

thassio-vinicius commented 4 years ago

this is still happening in 2020. Why is this issue closed?

omnibrain commented 3 years ago

We‘re facing the same issue!

eramudeep commented 3 years ago

I am also facing the same issue.

Alsania14 commented 3 years ago

i am also facing the same issue

shekhar12020 commented 3 years ago

We are also facing same issue. Randomly device stopped receiving notification. Then I need to restart the mobile network or wifi then it start working again and message get delivered from FCM.

andreififiita commented 3 years ago

Also it seems (for me at least) that messages sent to PWA / Chrome apps (using firebase web) have even longer delay, even hours if the phone or browser is not used. I have recently posted here: https://stackoverflow.com/questions/67178131/firebase-messaging-priority-high-not-working-on-android-chrome-pwa-app-delaye

andreififiita commented 3 years ago

@samtstern : You said that this issue was closed because it is not related to the code in this repo (which is understandable), but is there another issue opened somewhere else? If not, where can we open one so that the Firebase team takes us seriously?

shekhar12020 commented 3 years ago

Put below broadcast to send heartbeat to fcm on every launch:

sendBroadcast(new Intent("com.google.android.intent.action.GTALK_HEARTBEAT"));
sendBroadcast(new Intent("com.google.android.intent.action.MCS_HEARTBEAT"));

It's working for me.

EinfachHans commented 3 years ago

@shekhar12020 I'am encountering a similar issue. Sending these Heartbeats on App Launch solved it for sure? What do they do? I don't have to send them every Minute?

yujongu commented 3 years ago

Did anyone find a solution to this?

snowfluke commented 3 years ago

Having the same issue, notifications just stopped working and delivered in a huge delay

eggybot commented 3 years ago

I'm having the same issue for iOS devices. Do we have any issue with regards to the APN system? It looks like Firebase FCM has a bottleneck when it comes to iOS implementation.

Take note I'm experiencing this issue for the 2years ago but I could not find any good solution on this issue.

zeropi2021 commented 2 years ago

I have the same problems, especially noticeable it started to be a few days ago.

Delays from several minutes up to hours or complete lack of notifications. Various applications such as IFTTT or ewelink show the same problems... so this is not a problem on the application side.

samikedomitila commented 2 years ago

Having the same issue for both android and iOS, notifications just stopped working and delivered in a huge delay

aenonGit commented 2 years ago

same here, on android (pixel 3a) sometimes notifications with priority: high and ttl: 0 arrive with few seconds delay (making it useless for my usecase) or do not arrive at all.

xerdnew commented 1 year ago

Im also facing the same issue and i can find several issues about it but no solution. I have noticed that turning the wifi or cellular data off and on makes the notifications go through.

I am guessing the socket gets closed and waits for re-open. How can we fix this? Is there any KeepAlive option for Firebase Messaging service?

kroikie commented 1 year ago

Hi,

This seems to be enforced at the device level likely by the OEM. Is there a particular device you are seeing this on?

On Mon, Jul 10, 2023 at 6:50 AM xerdnew @.***> wrote:

Im also facing the same issue and i can find several issues about it but no solution. I have noticed that turning the wifi or cellular data off and on makes the notifications go through.

I am guessing the socket gets closed and waits for re-open. How can we fix this? Is there any KeepAlive option for Firebase Messaging service?

— Reply to this email directly, view it on GitHub https://github.com/firebase/quickstart-android/issues/307#issuecomment-1629010730, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASCVGDNR4OY2ZHP7PFJSBLXPQCC5ANCNFSM4DUB3VYA . You are receiving this because you commented.Message ID: @.***>

xerdnew commented 1 year ago

Hi, This seems to be enforced at the device level likely by the OEM. Is there a particular device you are seeing this on? On Mon, Jul 10, 2023 at 6:50 AM xerdnew @.> wrote: Im also facing the same issue and i can find several issues about it but no solution. I have noticed that turning the wifi or cellular data off and on makes the notifications go through. I am guessing the socket gets closed and waits for re-open. How can we fix this? Is there any KeepAlive option for Firebase Messaging service? — Reply to this email directly, view it on GitHub <#307 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASCVGDNR4OY2ZHP7PFJSBLXPQCC5ANCNFSM4DUB3VYA . You are receiving this because you commented.Message ID: @.>

Both emulators. One running Android 7 and one running Android 5 :(

sgserg commented 2 months ago

I'm seeing this mainly on older Android (7, 8 in 2024), while newer appear to be ok. Could it be device support ages with the device?