Fixed
Status Update
Comments
ni...@gmail.com <ni...@gmail.com> #2
I ran into the same issue and was going to fill another bug report (my original one was here : https://issuetracker.google.com/issues/110763358 )
There is another sample just in case.
There is another sample just in case.
ni...@gmail.com <ni...@gmail.com> #3
To add some info on the bug : I get it on my Galaxy S7 Edge with Android 7.0.
I tried to schedule the second worker not at the end of the doWork() method, but to schedule it through a Handler on MainThread, delayed by 1 to 10 seconds. Each time the first worker is reexecuted, and I don't have a clue why.
I tried to schedule the second worker not at the end of the doWork() method, but to schedule it through a Handler on MainThread, delayed by 1 to 10 seconds. Each time the first worker is reexecuted, and I don't have a clue why.
ni...@gmail.com <ni...@gmail.com> #4
Found another interesting thing, linked to my comment here : https://issuetracker.google.com/issues/110798652#comment8
The issue is also reproducible without requesting a worker from another worker...
Basically, have your app schedule a periodicWorker every day. Put a button that will schedule a onetimeworker to execute immediatly.
Every time I press the button, the periodicworker run.
That's why it's even worse when you schedule it in the periodicworker.
I looked at the code but don't get everything, I saw that when I schedule the onetimeworker (by pressing the button), the getEligibleWorkForScheduling in the schedule method of Schedulers class will return the periodic worker WorkSpec , then be called again, this time it return the onetime worker WorkSpec, and then the last time it returns an empty list.
The issue is also reproducible without requesting a worker from another worker...
Basically, have your app schedule a periodicWorker every day. Put a button that will schedule a onetimeworker to execute immediatly.
Every time I press the button, the periodicworker run.
That's why it's even worse when you schedule it in the periodicworker.
I looked at the code but don't get everything, I saw that when I schedule the onetimeworker (by pressing the button), the getEligibleWorkForScheduling in the schedule method of Schedulers class will return the periodic worker WorkSpec , then be called again, this time it return the onetime worker WorkSpec, and then the last time it returns an empty list.
ra...@google.com <ra...@google.com> #5
Thanks for the bug report. The fix should be available in alpha05.
Description
Devices/Android versions reproduced on: Pixel 2 XL (Android 8.1.0)
Sample project:
In the above sample we have 2 Workers:
- BrushTeethWorker
- PeriodicWorkRequestBuilder<BrushTeethWorker>(12, TimeUnit.HOURS)
- FlossWorker
- OneTimeWorkRequestBuilder<FlossWorker>()
Expected behavior:
- BrushTeethWorker run every ~12 hours
- FlossWorker run after each BrushTeethWorker run (so also ~12 hours)
Actual behavior:
- BrushTeethWorker runs repeatedly (until canceled)
- FlossWorker in turn also runs repeatedly (after each BrushTeethWorker run)
Since we want to have good hygiene we "brush teeth" about every 12 hours (BrushTeethWorker). At the end of brushing our teeth we may decide that we also want to floss (FlossWorker). Unfortunately, if we decide to floss while we're brushing our teeth then we end up brushing our teeth again (right after we've finished flossing). If we **don't** decide to floss then everything is good (we go about our day normally and brush our teeth every 12 hours). It is only when we decide to floss that we go a little crazy (keep brushing our teeth).
tl;dr requesting a worker from a running worker causes the first worker to run again right away, which will essentially cause both workers to continually execute over and over again forever (even if the periodic worker has been scheduled to run every ~12 hours)