What does WorkManager do with jobs after hitting JobScheduler limit of 100?

barnacle.m :

I have scoured the internet for info on this subject but nobody seems to be experiencing this issue anymore.

Remember this fun error?

java.lang.IllegalStateException: JobScheduler 100 job limit exceeded. We count 101 WorkManager jobs in JobScheduler; we have 50 tracked jobs in our DB; our Configuration limit is 50.

with

Caused by: java.lang.IllegalStateException: Apps may not schedule more than 100 distinct jobs

Well, despite switching a lot of jobs to do enqueueUniqueWork, it appears some of my users are still hitting that limit. My use case is for people with poor and no connectivity doing a lot of stuff offline and thereby creating lots of jobs to update resources on the remote server. I never had this problem with FirebaseJobDispatcher (at least I wasn't aware of it) and some people may be without signal for days, and what happens if somebody can't connect for weeks? It will easily build up hundreds of jobs. Hence, this error.

My question is what happens to these jobs when the limit is reached? Are they simply discarded by the scheduler? Am I losing people's data right now as I type this?

Update

Android Versions: Confirmed on 7.0, 8.0, 8.1, probably a lot more

WorkManager Version: 2.3.0

Rahul :

We fixed a bug recently, where there is a mismatch between WorkManagers tracking of jobs in JobScheduler and the actual state of the jobs. This happens in very rare cases, and I think that's what is going on in your case.

https://issuetracker.google.com/issues/149092520 was a recently reported bug. I fixed it before the bug was reported on the public tracker, because one of Google's apps ran into the same edge case.

This change (https://android-review.googlesource.com/c/platform/frameworks/support/+/1226859) has the fix. We should release this as part of WorkManager 2.3.2 very soon.

If you cannot wait, you can use a snapshot build that should be identical to the eventual release.

Here is the gradle snippet you will need:

repositories {
    google()
    maven { url 'https://ci.android.com/builds/submitted/6195753/androidx_snapshot/latest/repository/' }
}

dependencies {
  implementation "androidx.work:work-runtime:2.4.0-SNAPSHOT"
}

One other thing you might need to do is to get rid of stale jobs. It is as simple as calling JobScheduler.cancelAllJobs() before WorkManager is initialized. You can do it inside Application.onCreate() in your Application subclass.

If you need more help, please feel free to reach out on the bug tracker and I can help you out.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=11520&siteId=1