Reputation: 2200
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
Upvotes: 7
Views: 3159
Reputation: 21134
We fixed a bug recently, where there is a mismatch between WorkManager
s 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.
Upvotes: 1
Reputation: 6506
From the exception message it seems that you just have 20 WorkRequest tracked by WorkManager. The problem maybe due to a bug in the underlying implementation of JobScheduler, would be useful to understand on which devices/OS version you have seen these errors.
Also, the 100 Jobs limits is per app, and is not limited to WorkManager usage. If in your app (or in a SDK you are including) JobScheduler is used directly, this may help reaching the 100 jobs limits.
Lastly, can you please share which WorkManager version are you using?
Upvotes: 1