WAI
Status Update
Comments
ku...@google.com <ku...@google.com> #2
I'm not sure how to edit the description. But forgot to add that this will work when the app is in the foreground. It just doesn't work when you lock your device. I test this by moving the app to the background and then locking my device and checking the logs in Android Studio.
Description
I've observed WorkManager behavior breaking down when there are large numbers of workers. The particular scenario that I investigated involved ~2000 unconstrained periodic workers, each with a period of 1 day. In this situation, a couple of specific misbehaviors were evident:
androidx.work.diagnostics.REQUEST_DIAGNOSTICS
broadcast.I believe WM uses its own work-scheduling APIs internally for responding to the
REQUEST_DIAGNOSTICS
broadcast, so of course these might just be the same underlying issue. It feels like a crowding-out problem: that when there is a great deal of potentially runnable work, newly-scheduled work simply isn't considered in a timely way even when that work is marked as expedited. (The fact that expedited work does not appear to take precedence here also feels like a bug.)A background issue here is that arguably there should not be API for scheduling non-unique periodic work.
enqueuePeriodicWork()
should not exist.The scenario I described here arose because a developer who was new to the WM API mistakenly used
enqueuePeriodicWork()
instead ofenqueueUniquePeriodicWork()
; so over time the app scheduled a large number of duplicates. An app that genuinely wants to schedule multiple periodic workers with the same parameters & constraints and the same implementation class can already do so viaenqueueUniquePeriodicWork()
by synthesizing a new tag for each desired new instance. So, removingenqueuePeriodicWork()
wouldn't eliminate any actual capability -- it would just make it impossible for developers to accidentally shoot themselves in the foot like this.