-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
RemoteServiceException when using foreground service on Android API 26 #127
Comments
Can confirm that this is an Android 8 (API 26) specific issue. Was able to reproduce the crash on the simulator by calling |
Strange - I wonder if this is at all related to something happening with disk access (thus causing it to take longer than 5 seconds) as a proximate cause, using StrictMode to clean up things in general may be a useful pass in the codebase. I'm trying to understand (in my mental model) how a 5s violation could be API specific though, it doesn't really fit my model as I understand things. Odd. |
Yeah I'm not so sure about the 5s thingy either after narrowing it down to only API 26. Since it's so readily reproducible hopefully we'll hear from the notifee team soon. |
@mars-lan thanks for the info and sorry you've experienced this. I had a quick look, nothing stands out what could be causing the issue. I'll run it locally with the emulator and get back to you with more details. At the very least, I can put something in place to stop the crashing (i.e. disable foreground service for api 26) like you said. Hopefully, we can resolve this though, and get the other versions working too. |
@mars-lan I'm struggling to recreate this issue with API 26, with the following emulator: with notification:
Could you can paste some example code or show what payload you are passing to |
I wonder if it is timing dependent (the 5 second limit), and if the notification does some super slow network fetch or something it would trigger it? Is that possible - for the notification in any way to trigger some slow process that might take more than 5 seconds? Or maybe just for testing hack right into the code a delay to see if it reproduces the stack |
Main reason I am paying a lot of attention to this is that StrictMode and 5-seconds-to-start-foreground etc - if not pursued to a conclusive end that usually results in starting a worker thread and hiving slow things off into it - will result in flaky behavior forever, and future reports that are hard to reproduce / make working with the library touchy. I've seen that happen in the other lib (react-native-background-geolocation-android) I use that does foreground service (which could crash due to timing) and/or could ANR on startup until it was thoroughly scrubbed |
yeah that's what i was thinking it could be, like it's downloading an image and takes a while to start the foreground service 🤔 And, maybe it happens to be more common on older API versions. So the bug doesn't necessarily relate to the api version. |
@mikehardy just had a look at the library you mentioned, same issue was reported here transistorsoft/react-native-background-geolocation#976. I'm not sure though if there's something we can do in notifee to help. |
and here transistorsoft/react-native-background-geolocation#810 (comment). very similar logs @mars-lan. is this something you could try enabling, StrictMode to help debug? it could be something blocking the main thread? |
My guess it will end up being an "all of the above" approach - there are likely StrictMode violations in notifee and in @mars-lan app, and they all add up to a 5s failure I'm saying that because I'd bet 1% of apps or less are StrictMode clean, it's a safe bet :) |
@helenaford Whoa! Found the root cause! If I set
|
ah nice. OK, so would putting this in the docs to say be cautious about image sizes be a good fix for this? |
I think so. Maybe note that this seems to be an Android 8-specific issue. Another option is to move the image to Android drawable resource, which doesn't seem to suffer the same performance issue as local files. |
sounds good. thanks for bringing this issue to our attention and finding the bug. Would this be the same reason for the other api versions 22 - 25? If not, we can reopen invertase/react-native-notifee#291 |
Maybe put the file decode into bitmap (I think Notifee is handling the file fetch and decode?) into a background thread since it is disk access and update the notification with the bitmap once it's decoded? Is that possible? All the StrictMode violations and timeout items end up with solutions like that |
@helenaford I can confirm that by using an image with smaller dimension (128x128) or Android drawables directly for |
@helenaford after rolling out an update that uses Android drawable for |
I need a reaction for that where it's clear I'm unhappy but not at all at you personally. 😩 - thanks for the report |
FWIW also started seeing a few crashs on Android 10 (API 29). Definitely less common than API 26 though. |
@helenaford I assume notifee does the following when
How about simply swapping 1 & 2 to minimze the time between |
Hey @mars-lan , I'm looking into if we can fix the image loading, not sure how it's blocking as it's done with tasks but on my TODO is to check it in 'strict' mode. Unfortunately, it already does that, builds the notification, then does |
Sounds like it is actually doing 2 then 1 and 3 per the comment above descriptors, vs 1 3 then 2. Is it even possible to startForegroundService before you have the notification built? sounds like maybe not |
@mikehardy 3 takes the notification as one of the input so 1-3-2 isn't really an option here. Thanks for the explanation, @helenaford. Hopefully strict mode will reveal more. At least it's consistently reproducible on Andorid 8 emulator so hopefully it makes debugging easier. A somewhat hacky solution is to use startForegound instead if |
@helenaford Based on https://stackoverflow.com/questions/44425584/context-startforegroundservice-did-not-then-call-service-startforeground & https://issuetracker.google.com/issues/76112072, this seemss like a common issue for Android. In fact, there's simply no way to guarantee that the system will even start the foreground service within 5s, regardless how little work there is beteween Looks like the only foolproof way to avoid ANR is context.bindService + startService + service.startForeground. As a developer, I'd rather lose the ability to invoke |
Wow! Great digging @mars-lan - lot of electrons spent discussing this one. I'm a little confused on your last paragraph though - not to read too much in to it, but could your last sentence ("As a developer...") be considered a new paragraph? To be precise, are you saying that unless this API is fixed in general ("the ability to invoke I ask because it seemed as though the bindService style (or even JobService maybe - but bindService easier...) would fix it. Then you'd have displayNotification in the background and no crashes, which would be ideal. But I might be missing something you've already realized |
@mikehardy Thanks for the info. The trick in https://stackoverflow.com/a/57521350/9910298 seems promsing. However, https://stackoverflow.com/a/53286232/15875597 and other users' comments claimed that the approach doesn't work 100%. https://issuetracker.google.com/issues/76112072#comment158 says that the only reliable fix is to replace |
Can confirm that the same crash happens to Android 8-10 in production. Can we prioritize a fix? |
Likely yes - crash issues need priority. You can see from the timing on previous comment (11 days ago) this was immediately prior to google IO and I think you've actually participated in react-native-firebase repo in the intervening time on related issues? Hopefully not mis-remembering, at any rate that pulled my full attention for a while and I'm still unwinding the stack from there so I haven't been able to turn attention back here. Will tag this up at least |
I know it is a really tricky bug to fix, but any idea when the fix can be delivered? and is there any way that we can contribute to the native side of the project? |
@mikehardy sorry for poking again. We have some bandwidth on our end and could help investigating/resolving this issue. Any way we can contribute to the project? We still have occurrences of that in production and we can't really do anything about it. Not having news from notifee's side is also scary as we need to know if we'll have to implement our own solution or not. Could you please at least provide us with some insight on the progress of this issue ? 🙏 Thanks a lot |
I understand the desire to fix it, and I really appreciate the offer to help. Last time I asked internally we couldn't come up with a good way to extend access for collaboration but perhaps @Salakar has new ideas since then? In prep for development here I swept through just yesterday and got it cleaned up so changes here on my part are safe (#327 invertase/react-native-notifee#328 invertase/react-native-notifee#326). Steady forward progress but doesn't look exciting. Thanks for your patience |
@Salakar @mikehardy It's been 14 days without any news on this. We also tried to contact you via the "Contact Us" section of your website and still no signs of answers. I will re-iterate my question again regarding the help we can provide? This is becoming quite time sensitive for us and we'd like to at least have the sentiment that this is not becoming an inactive library without any support. We'd like to know if someone is looking at this or not and if we can participate in the elaboration of a solution. Also another question I would have regarding Notifee's support: Any idea when the Thank you very much! |
Only speaking to this:
Not including the core library changes, invertase/react-native-notifee@v1.5.0...master 6 releases since this issue was logged Obviously it would be better if this issue was fixed in one of those releases, but the library is receiving a steady amount of attention and effort, it is definitely under active development |
Any progress on this one? :) |
I must admit I was dreading the ping on this one - all I can offer is that the previous one from @sambegin is one of only a handful of messages I leave marked as unread in my software mail box. I have not made specific progress on it but am still slowly working towards it on the stack of todo items I've got in my Invertase queue. Cold comfort probably, but it is on the radar. |
@mikehardy thanks for the transparency. I understand that there's always competing priorities. It took me nearly a year to get invertase/react-native-notifee#126 to close so this one is still young :P |
You always log the tough ones @mars-lan ! 😆 |
Thanks for open sourcing the library! Will definitely take a deeper look into this one during the weekends. |
any updates ? |
We just got hit by this issue today - after releasing to production we saw at least 20% of crashes. Locally it is extremely hard to reproduce (both debug and release variant). Before integrating Notifee for foreground push, we used our own solution which never crashed so I was wondering why Notifee does crash. I am wondering does Notifee really has to use I see that in startForegroundService it says:
So I guess But then it looks like Notifee could change the condition from At least until the real fix is implemented. |
I dig in a bit more. From my finding it is not related to trampoline effect. It is only used because Notifee assumes that foreground push may be started from background and since So:
I think that starting foreground service from background that does not satisfy the conditions linked in (2) is rather an edge-case. Hence I propose we add a setting in diff --git a/android/src/main/java/app/notifee/core/ForegroundService.java b/android/src/main/java/app/notifee/core/ForegroundService.java
index 9150047..7d16768 100644
--- a/android/src/main/java/app/notifee/core/ForegroundService.java
+++ b/android/src/main/java/app/notifee/core/ForegroundService.java
@@ -45,7 +45,7 @@ public class ForegroundService extends Service {
intent.putExtra("notification", notification);
intent.putExtra("notificationBundle", notificationBundle);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && startServiceWithPromise) {
ContextHolder.getApplicationContext().startForegroundService(intent);
} else {
// TODO test this on older device For example, |
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
Thank you for your contributions. |
Hello @mikehardy, was there a resolution to this issue? |
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
Thank you for your contributions. |
Still getting this issue on Android 14 notifee version 9.1.8 :( |
i've tried to solve this in this pr - #1202 |
Start seeing the following crash when rolling out our new version that uses foreground service
So far the crash is limited to only Android 8.0 devices, but not sure if it's an artifact of the small rollout percentage or an actual version-specific issue.
Based on https://developer.android.com/about/versions/oreo/android-8.0-changes & https://developer.android.com/reference/android/app/Service#startForeground(int,%20android.app.Notification) it seems to suggest that
startForeground
wasn't called within 5 seconds of foreground service creation. Without any visibility into the code base, it's difficult to debug the issue further.The text was updated successfully, but these errors were encountered: