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

RuntimeException: Unable to start service org.wordpress.android.ui.uploads.UploadService@a38ce00 with Intent { cmp=... #18714

Closed
sentry-io bot opened this issue Jun 28, 2023 · 12 comments · May be fixed by #19755
Assignees

Comments

@sentry-io
Copy link

sentry-io bot commented Jun 28, 2023

Sentry Issue: JETPACK-ANDROID-80G

ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service com.jetpack.android/org.wordpress.android.ui.uploads.UploadService
    at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
    at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
    at android.os.Parcel.readParcelableInternal(Parcel.java:4786)
    at android.os.Parcel.readParcelable(Parcel.java:4754)
    at android.os.Parcel.createExceptionOrNull(Parcel.java:3017)
...
(19 additional frame(s) were not displayed)

RuntimeException: Unable to start service org.wordpress.android.ui.uploads.UploadService@a38ce00 with Intent { cmp=com.jetpack.android/org.wordpress.android.ui.uploads.UploadService (has extras) }: android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service com.jetpack.android/org.wordpress.android.ui.uploads.UploadService
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5457)
    at android.app.ActivityThread.-$$Nest$mhandleServiceArgs
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2675)
    at android.os.Handler.dispatchMessage(Handler.java:109)
    at android.os.Looper.loopOnce(Looper.java:206)
...
(5 additional frame(s) were not displayed)
@sentry-io
Copy link
Author

sentry-io bot commented Jul 12, 2023

Sentry issue: JETPACK-ANDROID-81N

@thomashorta
Copy link
Contributor

Sentry issue: JETPACK-ANDROID-81N

Even though this other issue is for media upload, the rest of the stacktrace is the same and the root cause is likely the same as well.

@ravishanker
Copy link
Contributor

@irfano - Pinging you, just in case if you have any thoughts on this. Wondering if this is anyway related to Android 13 upgrade!. Thank you

PS: If it is not, put back Requires Triage label, and unassign yourself

@irfano
Copy link
Member

irfano commented Aug 22, 2023

ForegroundServiceStartNotAllowedException is caused by restrictions on background starts. These rules are introduced with Android 12, and this crash also occurs on Android 12 and Android 14 devices.
As a solution, we should migrate UploadService to WorkManager, and that task will be mandatory for Android 14 migration. This is already on our roadmap.
So, we can keep this issue open until we fix it in the Android 14 migration.

@irfano irfano removed their assignment Aug 22, 2023
@sentry-io
Copy link
Author

sentry-io bot commented Sep 4, 2023

Sentry issue: WORDPRESS-ANDROID-2CJG

@thomashorta thomashorta self-assigned this Dec 6, 2023
@thomashorta
Copy link
Contributor

I started looking into this today since this week we are trying to get rid of as many crashes as we can and even though this is not a high-impact crash, it is something affecting several users on Android 12+ and will be mandatory when targeting SDK 34 anyway, so better to start getting things in place for this UploadService update to WorkManager.

@thomashorta
Copy link
Contributor

Well, this task proved to be way more challenging than expected (and I was already expecting it to be very challenging) but the UploadService is used and called by so many different places, and it handles a lot of logic (including subscribing to the EventBus), so refactoring it to use only Workers is not an easy task.

Thanks, @ravishanker for starting a PR with some code refactoring to use Workers: #19755. I still have some concerns about how to do that refactor though, but it's nice to see you started it!


During this week I was able to get a better understanding of how WorkManager works and its limitations and also get some insights related to UploadService and possible crash causes. I also opened a PR (#19762) adding logs for identifying the caller/source that started the Service, so we have better breadcrumbs in Sentry for understanding the issue and aiding the future task of refactoring this class.

Some insights about our code:

  • There is a UploadWorker in the code that calls the Service. I believe this was a start to migrating uploads to use WorkManager, but right now it simply uses the UploadService and therefore has the same issues when started from the background.
  • That UploadWorker is being enqueued in a Periodic Task which means it is likely executed in the background at some point, and since it uses UploadService this means a guaranteed crash. The breadcrumbs from JETPACK-ANDROID-80G don't seem to match that flow, but a few events in WORDPRESS-ANDROID-2CJG look like they could be caused by that.
  • Another flow that starts the UploadWorker from the background is when post/media is uploaded in the app with no internet connection and thanks to the WorkRequest constraints the Work only starts when the device is back online at a later time, so the app could be in background at that point, causing the crash (again not matching the breadcrumbs from issues in JETPACK-ANDROID-80G but matching a few in WORDPRESS-ANDROID-2CJG).
  • The UploadWorker doesn't really wait for the UploadService to finish, since it doesn't observe/communicate with it to know information about the upload status. That means the Worker starts, launches the UploadService, and finishes. This is just a side note, but not what I was expecting.

Regarding using WorkManager for post/media uploads:

  • We need to be careful about how we will spawn those WorkRequests for upload since Workers can only run for 10 minutes, so I believe we should aim to break the Workers per upload instead of having a single Worker running a for loop, since long-running Workers would have the same "foreground" limitation issue.

Copy link
Author

sentry-io bot commented Jan 8, 2024

Sentry issue: WORDPRESS-ANDROID-2CYQ

@thomashorta thomashorta removed their assignment Jan 8, 2024
Copy link
Author

sentry-io bot commented Jan 15, 2024

Sentry issue: WORDPRESS-ANDROID-2CY8

@irfano
Copy link
Member

irfano commented Jan 22, 2024

@antonis, I assigned this to you since you said in #19987 (comment) that you will monitor this during the beta. Feel free to close the issue if there are no more reports or unassign yourself after completing your monitoring and if the crash persists.

@antonis
Copy link
Contributor

antonis commented Jan 25, 2024

Adding for future reference the steps that led to a crash for me (Pixel 5, Android 14) but not consistently were:

  1. set the device in flight mode
  2. add a new post
  3. add a big media (e.g. video)
  4. close the app
  5. open and add another media
  6. turn the flight mode off
  7. wait for the crash to happen🤞

@antonis
Copy link
Contributor

antonis commented Feb 12, 2024

Closing with #19987 since no new crashes were recorded in 24.1

@antonis antonis closed this as completed Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants