Fixed
Status Update
Comments
su...@google.com <su...@google.com> #2
We have same issue.
Version used: WorkManager 2.1.0-alpha01
Devices/Android versions reproduced on: mostly Android 5 & 6
Fatal Exception: java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x4000010 (has extras) } in androidx.work.impl.constraints.trackers.NetworkStateTracker$NetworkStateBroadcastReceiver@c5142c8
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:876)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
Caused by java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@64a6d62 rejected from java.util.concurrent.ScheduledThreadPoolExecutor@16d09ef3[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2011)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:793)
at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:298)
at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:503)
at java.util.concurrent.Executors$DelegatedScheduledExecutorService.schedule(Executors.java:644)
at androidx.work.impl.background.systemalarm.WorkTimer.startTimer(WorkTimer.java:82)
at androidx.work.impl.background.systemalarm.DelayMetCommandHandler.onAllConstraintsMet(DelayMetCommandHandler.java:100)
at androidx.work.impl.constraints.WorkConstraintsTracker.onConstraintMet(WorkConstraintsTracker.java:150)
at androidx.work.impl.constraints.controllers.ConstraintController.updateCallback(ConstraintController.java:134)
at androidx.work.impl.constraints.controllers.ConstraintController.onConstraintChanged(ConstraintController.java:141)
at androidx.work.impl.constraints.trackers.ConstraintTracker.setState(ConstraintTracker.java:103)
at androidx.work.impl.constraints.trackers.NetworkStateTracker$NetworkStateBroadcastReceiver.onReceive(NetworkStateTracker.java:170)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
Version used: WorkManager 2.1.0-alpha01
Devices/Android versions reproduced on: mostly Android 5 & 6
Fatal Exception: java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x4000010 (has extras) } in androidx.work.impl.constraints.trackers.NetworkStateTracker$NetworkStateBroadcastReceiver@c5142c8
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:876)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
Caused by java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@64a6d62 rejected from java.util.concurrent.ScheduledThreadPoolExecutor@16d09ef3[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2011)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:793)
at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:298)
at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:503)
at java.util.concurrent.Executors$DelegatedScheduledExecutorService.schedule(Executors.java:644)
at androidx.work.impl.background.systemalarm.WorkTimer.startTimer(WorkTimer.java:82)
at androidx.work.impl.background.systemalarm.DelayMetCommandHandler.onAllConstraintsMet(DelayMetCommandHandler.java:100)
at androidx.work.impl.constraints.WorkConstraintsTracker.onConstraintMet(WorkConstraintsTracker.java:150)
at androidx.work.impl.constraints.controllers.ConstraintController.updateCallback(ConstraintController.java:134)
at androidx.work.impl.constraints.controllers.ConstraintController.onConstraintChanged(ConstraintController.java:141)
at androidx.work.impl.constraints.trackers.ConstraintTracker.setState(ConstraintTracker.java:103)
at androidx.work.impl.constraints.trackers.NetworkStateTracker$NetworkStateBroadcastReceiver.onReceive(NetworkStateTracker.java:170)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
su...@yahooinc.com <su...@yahooinc.com> #3
liujian16@: Are you sure this is happening on Android 6? Because the stack trace points to DelayMetCommandHandler (which is something that the AlarmManager based implementation uses) which is only used on API <= 22.
nihansin@: Sorry its not clear what you meant by
"WorkManager 2.1.0-alpha01
I know 2.1.0-alpha02 is out but I cannot test it as I CANNOT reproduce this issue on both alpha01 and 02."
Did you mean that you cannot reproduce this on your own but you see this happen in production ?
My guess is something like this might be happening:
If you have a Worker in RUNNING state, and you have been asked to stop (either because constraints are no longer met / or if you called cancel()) your Worker still needs to cooperatively cancel.
If your Worker never stops running, then WorkTimer will try and shutdown your Worker again (in 10 minutes). This time that will fail, because the Executor has already been shutdown.
This typically stems from a bug in your code (because your Worker never stopped).
Can you please turn on WorkManager's logging so it will better help us diagnose the problem ?
For this you need to use custom initialization. Something like:
Configuration configuration = new Configuration.Builder()
.setMinimumLoggingLevel(Log.VERBOSE)
.build();
WorkManager.initialize(context, configuration);
Make sure you disable the default initializer.
nihansin@: Sorry its not clear what you meant by
"WorkManager 2.1.0-alpha01
I know 2.1.0-alpha02 is out but I cannot test it as I CANNOT reproduce this issue on both alpha01 and 02."
Did you mean that you cannot reproduce this on your own but you see this happen in production ?
My guess is something like this might be happening:
If you have a Worker in RUNNING state, and you have been asked to stop (either because constraints are no longer met / or if you called cancel()) your Worker still needs to cooperatively cancel.
If your Worker never stops running, then WorkTimer will try and shutdown your Worker again (in 10 minutes). This time that will fail, because the Executor has already been shutdown.
This typically stems from a bug in your code (because your Worker never stopped).
Can you please turn on WorkManager's logging so it will better help us diagnose the problem ?
For this you need to use custom initialization. Something like:
Configuration configuration = new Configuration.Builder()
.setMinimumLoggingLevel(Log.VERBOSE)
.build();
WorkManager.initialize(context, configuration);
Make sure you disable the default initializer.
su...@google.com <su...@google.com> #4
I will investigate this further on my end as well.
su...@yahooinc.com <su...@yahooinc.com> #5
Yes, I meant that I cannot reproduce it in my tests.
Here are some points.
- I skip the job if there is an already active job when doWork is called.
- I am never call cancell and I exit with success if job takes longer than
9 minutes. However, I do do batch processing and it may be that one of the
runs in the batch might have taken more than 10 minutes.
On Thu, 23 May 2019, 18:06 , <buganizer-system@google.com> wrote:
Here are some points.
- I skip the job if there is an already active job when doWork is called.
- I am never call cancell and I exit with success if job takes longer than
9 minutes. However, I do do batch processing and it may be that one of the
runs in the batch might have taken more than 10 minutes.
On Thu, 23 May 2019, 18:06 , <buganizer-system@google.com> wrote:
su...@google.com <su...@google.com> #6
"I skip the job if there is an already active job when doWork is called."
What do you mean by that ?
What kind of result are you returning ?
"I am never call cancell and I exit with success if job takes longer than
9 minutes. "
How are you accounting for time ? Are you regularly polling inside your Worker ?
What do you mean by that ?
What kind of result are you returning ?
"I am never call cancell and I exit with success if job takes longer than
9 minutes. "
How are you accounting for time ? Are you regularly polling inside your Worker ?
su...@yahooinc.com <su...@yahooinc.com> #7
I have a utility method to check the status of the jobs by tag
fun Worker.isRunning(tag: String): Boolean {
val instance = androidx.work.WorkManager.getInstance(applicationContext)
val statuses = instance.getWorkInfosByTag(tag)
try {
var running = false
val workInfoList = statuses.get()
for (workInfo in workInfoList) {
val state = workInfo.state
running = (state == WorkInfo.State.RUNNING)
}
return running
} catch (e: ExecutionException) {
e.printStackTrace()
return false
} catch (e: InterruptedException) {
e.printStackTrace()
return false
}
}
This is a periodic work. I always return Result.success() regardless what I
do when doWork run.
I assign current millis to a value in the beginning of doWork, call my
method that does what I want to do and check time on each loop.
My method is a simple for each loop that pulls a list from app dB and goes
through items.
On Thu, 23 May 2019, 18:20 , <buganizer-system@google.com> wrote:
fun Worker.isRunning(tag: String): Boolean {
val instance = androidx.work.WorkManager.getInstance(applicationContext)
val statuses = instance.getWorkInfosByTag(tag)
try {
var running = false
val workInfoList = statuses.get()
for (workInfo in workInfoList) {
val state = workInfo.state
running = (state == WorkInfo.State.RUNNING)
}
return running
} catch (e: ExecutionException) {
e.printStackTrace()
return false
} catch (e: InterruptedException) {
e.printStackTrace()
return false
}
}
This is a periodic work. I always return Result.success() regardless what I
do when doWork run.
I assign current millis to a value in the beginning of doWork, call my
method that does what I want to do and check time on each loop.
My method is a simple for each loop that pulls a list from app dB and goes
through items.
On Thu, 23 May 2019, 18:20 , <buganizer-system@google.com> wrote:
ap...@google.com <ap...@google.com> #8
Can you please send us a sample app? Failing that, can you send us an unobfuscated stacktrace?
Description
Version used: Alpha 10
Devices/Android versions reproduced on: Nvidia (100%)
stacktrace:
ConnectivityManager.java in android.net.ConnectivityManager.unregisterNetworkCallback at line 3106
NetworkStateTracker.java in androidx.work.impl.constraints.trackers.NetworkStateTracker.stopTracking at line 94
ConstraintTracker.java in androidx.work.impl.constraints.trackers.ConstraintTracker.removeListener at line 79
ConstraintController.java in androidx.work.impl.constraints.controllers.ConstraintController.replace at line 98
GreedyScheduler.java in androidx.work.impl.background.greedy.GreedyScheduler.removeConstraintTrackingFor at line 150
Processor.java in androidx.work.impl.Processor.onExecuted at line 228
Processor.java in androidx.work.impl.Processor$FutureListener.run at line 258
Handler.java in android.os.Handler.handleCallback at line 751
Handler.java in android.os.Handler.dispatchMessage at line 95
Looper.java in android.os.Looper.loop at line 154
ActivityThread.java in android.app.ActivityThread.main at line 6120
java.lang.reflect.Method in invoke
ZygoteInit.java in com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run at line 865
ZygoteInit.java in com.android.internal.os.ZygoteInit.main at line 755