Android-job: Android O - java.lang.RuntimeException: An error occurred while executing doInBackground()

Created on 24 Aug 2017  Â·  61Comments  Â·  Source: evernote/android-job

Crash happened with 1.2.0-alpha3 on Pixel running 8.0.0. Here's the stacktrace:

Fatal Exception: java.lang.RuntimeException: An error occurred while executing doInBackground()
       at android.os.AsyncTask$3.done(AsyncTask.java:353)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
       at java.util.concurrent.FutureTask.run(FutureTask.java:271)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
       at java.lang.Thread.run(Thread.java:764)
Caused by java.lang.SecurityException: Caller no longer running, last stopped +25s437ms because: timed out while starting
       at android.os.Parcel.readException(Parcel.java:1942)
       at android.os.Parcel.readException(Parcel.java:1888)
       at android.app.job.IJobCallback$Stub$Proxy.dequeueWork(IJobCallback.java:191)
       at android.app.job.JobParameters.dequeueWork(JobParameters.java:196)
       at android.support.v4.app.JobIntentService$JobServiceEngineImpl.dequeueWork(JobIntentService.java:309)
       at android.support.v4.app.JobIntentService.dequeueWork(JobIntentService.java:627)
       at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:384)
       at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:377)
       at android.os.AsyncTask$2.call(AsyncTask.java:333)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
       at java.lang.Thread.run(Thread.java:764)
bug

Most helpful comment

I've had over 127 users with this crash with production code. This error, closed, it should not be.

All 61 comments

This is a known issue: https://issuetracker.google.com/issues/63622293

Can you try to use version 1.2.0-alpha4? Then the issue could be gone.

Closing because of inactivity.

Issue still present as of 1.2.0-RC3.

Issue, maybe not the same but similar is still present in 1.2.0:

Fatal Exception: java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:353)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by java.lang.SecurityException: Caller no longer running, last stopped +663ms because: timed out while starting
at android.os.Parcel.readException(Parcel.java:1942)
at android.os.Parcel.readException(Parcel.java:1888)
at android.app.job.IJobCallback$Stub$Proxy.dequeueWork(IJobCallback.java:191)
at android.app.job.JobParameters.dequeueWork(JobParameters.java:196)
at android.support.v4.app.JobIntentService$JobServiceEngineImpl.dequeueWork(JobIntentService.java:314)
at android.support.v4.app.JobIntentService.dequeueWork(JobIntentService.java:639)
at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:389)
at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:382)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)

My question is, is this a long running job issue? I can't find limits stated anywhere for jobs, but guessing they exist? And this is a problem as I'm doing network communication and timeouts would cause havoc on run length limits...

@KennyGoers Which version of the support library are you using? My problems went away when I upgraded from the beta version to the production version.

This is in the 26.1.0 version, build with the 3.0 Android Studio and I haven't seen the problem myself with a Nexus 5X with 8.0 and not 8.1, only shows with my users in Fabric and it's pretty common there. I don't know if it just happens occasionally and reruns later or continually.

I've had over 127 users with this crash with production code. This error, closed, it should not be.

Can you please file a ticket at b.android.com? That's an issue in the support library. Thanks.

@vRallev @KennyGoers did you file an issue?

Caused by java.lang.SecurityException: Caller no longer running, last stopped +1s803ms because: unexpectedly disconnected
       at android.os.Parcel.readException(Unknown Source:69)
       at android.os.Parcel.readException(Unknown Source:10)
       at android.app.job.IJobCallback$Stub$Proxy.completeWork(Unknown Source:29)
       at android.app.job.JobParameters.completeWork(Unknown Source:12)
       at android.support.v4.app.JobIntentService$JobServiceEngineImpl$WrapperWorkItem.complete(JobIntentService.java:267)
       at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:393)
       at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:382)
       at android.os.AsyncTask$2.call(Unknown Source:22)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
       at java.lang.Thread.run(Thread.java:764)
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:353)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.SecurityException: Caller no longer running, last stopped +2s519ms because: timed out while starting
at android.os.Parcel.readException(Parcel.java:2004)
at android.os.Parcel.readException(Parcel.java:1950)
at android.app.job.IJobCallback$Stub$Proxy.dequeueWork(IJobCallback.java:191)
at android.app.job.JobParameters.dequeueWork(JobParameters.java:208)
at android.support.v4.app.JobIntentService$f.b(SourceFile:314)
at android.support.v4.app.JobIntentService.d(SourceFile:639)
at android.support.v4.app.JobIntentService$a.a(SourceFile:389)
at android.support.v4.app.JobIntentService$a.doInBackground(SourceFile:382)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
... 3 more
java.lang.SecurityException: Caller no longer running, last stopped +2s519ms because: timed out while starting
at android.os.Parcel.readException(Parcel.java:2004)
at android.os.Parcel.readException(Parcel.java:1950)
at android.app.job.IJobCallback$Stub$Proxy.dequeueWork(IJobCallback.java:191)
at android.app.job.JobParameters.dequeueWork(JobParameters.java:208)
at android.support.v4.app.JobIntentService$f.b(SourceFile:314)
at android.support.v4.app.JobIntentService.d(SourceFile:639)
at android.support.v4.app.JobIntentService$a.a(SourceFile:389)
at android.support.v4.app.JobIntentService$a.doInBackground(SourceFile:382)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)

Optimizely recently fixed a similar-looking issue at https://github.com/optimizely/android-sdk/pull/193. Could this problem be the same?

That fix would be sufficient for us. We're seeing this as one of our top crashes in an app with widespread use as well, increasing each day the more users that onboard via O.

We're seeing this issue with a high number of crashes +100K.

I have experienced this crash using android-job version 1.2.5. Downgraded it to 1.2.2 and the issue was gone.

@henriquenfaria this is not fixing it. We have this exact issue as far back as 1.2.1.

I am wondering that JobScheduler really have timeout.

Interestingly, only seeing this issue reported from HUAWEI devices. Anyone else seeing that?

We see it on all kinds of devices. We're in the 1000s of users with this crash.

Our spread is:
Samsung 55%
Google 17%
HMD Global 12%
Huawei 4%
Other… 12%

From what we can tell yigit's job library doesn't have this issue, so we are experimenting with moving off the evernote library since it's getting to be a year with this issue at large.

https://github.com/yigit/android-priority-jobqueue

I've found a way for me to reproduce this crash. I only need to start debug from Android Studio for my app.
Always getting

Caused by: java.lang.SecurityException: Caller no longer running, last stopped +12s589ms because: timed out while starting

I hope this helps to find a solution for this. I'm willing to investigate if anyone wants me to try something.

I can also confirm that this crash happens occasionally across all kind of devices. Unfortunately I also couldn't find a way to reliably reproduce the issue...

EDIT: @Jeff11 how did you reproduce the issue? Can you please provide all steps?

@Agraphie I just needed to start the app with the debugger from Android Studio and would get this crash. My app has a rather big Application class and JobManager.create(this) is in onCreate().

Strangely, the crash is not happening anymore when starting the debugger.

has anyone find solution ? I am facing this problem when I start app with debugger

I have the same issue with Android O

Hi evernote,

we had this issue, we made a child class out of the JobIntentSerivce. And started using the child class throughout our project.
we also wrapped the dequeWork method in the framework with try catch.

package android.support.v4.app;

import timber.log.Timber;

public abstract class MyJobIntentService extends JobIntentService {

@Override
GenericWorkItem dequeueWork() {

    try {
        return super.dequeueWork();
    } catch (SecurityException ignored) {
        Timber.e(ignored);
    }

    return null;
}

}

Take a note here, i have mentioned the same package name, to get access to GenericWorkItem

Thanks for the snippet. I'll add this workaround in the next version.

This should be fixed in version 1.3.0-alpha02. Please give it a try and let me know if it works for you. Thanks for all the comments and help!

Nice, @vRallev! Will try as soon as 1.3.0-alpha02 is available.

Got this on 1.3.0-alpha03 without WorkManager on different Huawei devices running Android 8.0.0

Fatal Exception: java.lang.RuntimeException: An error occurred while executing doInBackground()
       at android.os.AsyncTask$3.done(AsyncTask.java:365)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
       at java.util.concurrent.FutureTask.run(FutureTask.java:271)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
       at java.lang.Thread.run(Thread.java:784)
Caused by java.lang.SecurityException: Caller no longer running, last stopped +1m17s624ms because: timed out while stopping
       at android.os.Parcel.readException(Parcel.java:1945)
       at android.os.Parcel.readException(Parcel.java:1891)
       at android.app.job.IJobCallback$Stub$Proxy.completeWork(IJobCallback.java:218)
       at android.app.job.JobParameters.completeWork(JobParameters.java:220)
       at android.support.v4.app.v$f$a.b(JobIntentService.java:267)
       at android.support.v4.app.v$a.doInBackground(JobIntentService.java:2393)
       at android.os.AsyncTask$2.call(AsyncTask.java:345)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
       at java.lang.Thread.run(Thread.java:784)

I have the same issue as @Jeff11 in a Huawei running 8.0.0 using 1.3.0-alpha03

Caused by java.lang.SecurityException: Caller no longer running, last stopped +3s72ms because: timed out while stopping
       at android.os.Parcel.readException(Parcel.java:1945)
       at android.os.Parcel.readException(Parcel.java:1891)
       at android.app.job.IJobCallback$Stub$Proxy.completeWork(IJobCallback.java:218)
       at android.app.job.JobParameters.completeWork(JobParameters.java:220)
       at android.support.v4.app.JobIntentService$JobServiceEngineImpl$WrapperWorkItem.complete(JobIntentService.java:267)
       at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:393)
       at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:382)
       at android.os.AsyncTask$2.call(AsyncTask.java:345)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
       at java.lang.Thread.run(Thread.java:784)

Having this issue as well... so the try/catch workaround isn't enough?

@vRallev I still got crash in 1.3.0-alpha03
If you look at the source code of JobServiceContext, you should try to do something with doCompleteWork as well

HI @vRallev can you try this, i try to replace the CompatJobEngine mJobImpl by new one and try-catch both dequeueWork and completeWork methods :

`public abstract class SafeJobIntentService extends JobIntentService {
public CompatJobEngine mJobImpl;

@Override
public void onCreate() {
    super.onCreate();
    if (Build.VERSION.SDK_INT >= 26) {
        mJobImpl = new JobServiceEngineImplEx(this);
    } else {
        mJobImpl = null;
    }
}

@Override
GenericWorkItem dequeueWork() {
    try {
        return super.dequeueWork();
    } catch (SecurityException e) {
        e.printStackTrace();
        return null;
    }
}

/**
 * Implementation of a JobServiceEngine for interaction with JobIntentService.
 */
@RequiresApi(26)
static final class JobServiceEngineImplEx extends JobServiceEngine
        implements JobIntentService.CompatJobEngine {
    static final String TAG = "JobServiceEngineImpl";
    static final boolean DEBUG = false;
    final JobIntentService mService;
    final Object mLock = new Object();
    JobParameters mParams;

    final class WrapperWorkItem implements JobIntentService.GenericWorkItem {
        final JobWorkItem mJobWork;

        WrapperWorkItem(JobWorkItem jobWork) {
            mJobWork = jobWork;
        }

        @Override
        public Intent getIntent() {
            return mJobWork.getIntent();
        }

        @Override
        public void complete() {
            try {
                synchronized (mLock) {
                    if (mParams != null) {
                        mParams.completeWork(mJobWork);
                    }
                }
            } catch (Exception e) {
                // Exception Here
                e.printStackTrace();
            }
        }
    }

    JobServiceEngineImplEx(JobIntentService service) {
        super(service);
        mService = service;
    }

    @Override
    public IBinder compatGetBinder() {
        return getBinder();
    }

    @Override
    public boolean onStartJob(JobParameters params) {
        if (DEBUG) Log.d(TAG, "onStartJob: " + params);
        mParams = params;
        // We can now start dequeuing work!
        mService.ensureProcessorRunningLocked(false);
        return true;
    }

    @Override
    public boolean onStopJob(JobParameters params) {
        if (DEBUG) Log.d(TAG, "onStartJob: " + params);
        boolean result = mService.doStopCurrentWork();
        synchronized (mLock) {
            // Once we return, the job is stopped, so its JobParameters are no
            // longer valid and we should not be doing anything with them.
            mParams = null;
        }
        return result;
    }

    /**
     * Dequeue some work.
     */
    @Override
    public JobIntentService.GenericWorkItem dequeueWork() {
        JobWorkItem work = null;
        try {
            synchronized (mLock) {
                if (mParams == null) {
                    return null;
                }
                work = mParams.dequeueWork();
            }
        } catch (Exception e) {
            // Exception Here
            e.printStackTrace();
        }
        if (work != null) {
            work.getIntent().setExtrasClassLoader(mService.getClassLoader());
            return new WrapperWorkItem(work);
        } else {
            return null;
        }
    }
}

}
`

@vRallev base on @nguyenvp08 's suggestion, I create a new pull request #502 to fix this issue. Please review it and add to new release. Thanks!

Does anyone have a reliable repro case for this one? Only seeing it in the wild, haven't been able to repro it yet myself.

I'm sorry for the delay. I'll take a look the next days. Thanks for all the feedback!

I've published a new release. Please let me know if this issue is fixed for you. Thanks for the PR! https://github.com/evernote/android-job/releases/tag/v1.3.0-alpha04

@nguyenvp08
Thanks for the contribution.

I didn't use this lib but has same crash on my app. If this fix been proved, Can I copy and paste this snippet into my own app?

@vRallev Would it be possible to release a 1.2.7 version as 1.2.6 + this fix only?

1.3.0 is in alpha06 (which uses WorkManager, also in alpha) so it doesn't feel stable yet for a production app right now, so I'm afraid to upgrade to 1.3.0-alpha06 but would not mind a stable 1.2.7 just with this fix.

This crash happens a lot in our app so I am looking for ways to get this fix quickly.

Thank you in advance,
Alex

The Version 1.3.0-alpha04 is working great in my production app it does not crash anymore sometimes crash but really normal thing

@galex Sorry, but I won't do this. You can use 1.3.0 WITHOUT WorkManager and shouldn't have any problems.

@vRallev I understand but I can't use something with "alpha" in its name our production app. Do you have any idea when 1.3.0 will be official / stable ?

Soonish if no errors are reported. I'm on vacation for a week, probably after that.

Hi everyone!

I'm not using android-job in my current project, but I also have this error (mostly in Huawei devices):

java.lang.RuntimeException: at android.os.AsyncTask$3.done (AsyncTask.java:365) at java.util.concurrent.FutureTask.finishCompletion (FutureTask.java:383) at java.util.concurrent.FutureTask.setException (FutureTask.java:252) at java.util.concurrent.FutureTask.run (FutureTask.java:271) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636) at java.lang.Thread.run (Thread.java:784) Caused by: java.lang.SecurityException: at android.os.Parcel.readException (Parcel.java:1945) at android.os.Parcel.readException (Parcel.java:1891) at android.app.job.IJobCallback$Stub$Proxy.dequeueWork (IJobCallback.java:191) at android.app.job.JobParameters.dequeueWork (JobParameters.java:196) at android.support.v4.app.JobIntentService$JobServiceEngineImpl.dequeueWork (JobIntentService.java:314) at android.support.v4.app.JobIntentService.dequeueWork (JobIntentService.java:639) at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground (JobIntentService.java:2389) at android.os.AsyncTask$2.call (AsyncTask.java:345) at java.util.concurrent.FutureTask.run (FutureTask.java:266)

How stable is 1.3.0-alpha06? I'm seeing this issue on Android 8 devices (LG-H870DS & Motorola G6) with version 1.2.6.

@ruha9005

If you not use android-job, you can check this SafeJobIntentService

The code was copy from android-job and just for solving the crash

If you aren't using android-job already, you should use the WorkManager library as it is created and maintained by Google. Evernote suggest using this library from now on.

The WorkManager library is still very much alpha and has been very buggy, especially with periodic jobs. I strongly suggest staying with the default android-job implementation for now. I certainly am

Is there any solution for this issue? Because it seems that this issue occurs while using WorkManager as well.

Hi there ! Still no solution ? It's the same for me, I can't put your alpha version in production...
Is there any fix schedule for the 1.2 version ?

I've made a version 1.2.7 which is 1.2.6 plus a fix for this issue. Feel free to build it and use it locally for your project.

Here's the branch: https://github.com/galex/android-job/tree/1.2.7

I will test 1.2.7 in our app.
Is the fix solution based on the same thing like this one?
https://github.com/optimizely/android-sdk/issues/194

I will test 1.2.7 in our app.
Is the fix solution based on the same thing like this one?
optimizely/android-sdk#194

Seems to me, yes.

I'm curious if the above solution has been verified and if there are any plans to release 1.2.7?

A release with the fix for this would be much appreciated.

+1 to releasing a fix

Is there any solution found for below exception, I am using androidx 1.0.0
only android Oreo users facing this problem for my app

Fatal Exception: java.lang.RuntimeException: An error occurred while executing doInBackground()
       at android.os.AsyncTask$3.done(AsyncTask.java:353)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
       at java.util.concurrent.FutureTask.run(FutureTask.java:271)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
       at java.lang.Thread.run(Thread.java:764)


Caused by java.lang.SecurityException: Caller no longer running, last stopped +325ms because: timed out while starting
       at android.os.Parcel.readException(Parcel.java:2029)
       at android.os.Parcel.readException(Parcel.java:1975)
       at android.app.job.IJobCallback$Stub$Proxy.dequeueWork(IJobCallback.java:191)
       at android.app.job.JobParameters.dequeueWork(JobParameters.java:208)
       at androidx.core.app.JobIntentService$JobServiceEngineImpl.dequeueWork(JobIntentService.java:315)
       at androidx.core.app.JobIntentService.dequeueWork(JobIntentService.java:640)
       at androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:390)
       at androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:383)
       at android.os.AsyncTask$2.call(AsyncTask.java:333)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
       at java.lang.Thread.run(Thread.java:764)

Please help with the solution

@sureshmaidaragi1919 any luck?
I still have this issue and I have no idea why this is happening...

Is there any new androidx release to solve this problem ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tatocaster picture tatocaster  Â·  6Comments

vibin picture vibin  Â·  3Comments

krokyze picture krokyze  Â·  3Comments

judemanutd picture judemanutd  Â·  4Comments

karntrehan picture karntrehan  Â·  5Comments