Skip to content

Android Crash - Tried to finish non-existent task with id 2 #202

@cristianoccazinsp

Description

@cristianoccazinsp

Just received a random Android crash from the crash reporting tool. I know the app's only headless task with a timeout value comes from this library, but I haven't been able to reproduce the scenario where such a weird crash would happen. I'm also aware that Samsung devices are a piece of crap and will kill your app as soon as possible, and is most likely the reason for the crash

The crash happened from a headless task that didn't run with the app previously initialized (with an UI / main activity). See crash logs at the end.

After tracing the error, I ended up here: https://github.com/facebook/react-native/blob/0.61-stable/ReactAndroid/src/main/java/com/facebook/react/jstasks/HeadlessJsTaskContext.java#L202 , here https://github.com/facebook/react-native/blob/0.61-stable/ReactAndroid/src/main/java/com/facebook/react/jstasks/HeadlessJsTaskContext.java#L111 and here https://github.com/facebook/react-native/blob/0.61-stable/ReactAndroid/src/main/java/com/facebook/react/jstasks/HeadlessJsTaskContext.java#L165

The above lines hint me that some headless task with a timeout failed to be stopped with the above exception. So far the only headless task with timeout comes from BackgroundFetch.registerHeadlessTask(headlessTask), so I wonder if this crash has been seen already.

Also wonder if this is more of a react native bug itself, looks like a bit aggressive to kill the app just because the task no longer exists. Thoughts?

Your Environment

  • Plugin version: 2.7.1
  • Platform: Android
  • OS version: 9
  • Device manufacturer / model: Samsung SM-G965U1
  • React Native version (react-native -v): 0.61.5
  • Plugin config
 BackgroundFetch.configure({
      minimumFetchInterval: 60,
      stopOnTerminate: false,
      startOnBoot: true, 
      enableHeadless: true
    });

Expected Behavior

No crash if the task times out.

Actual Behavior

Looks like the task timed out and the app crashed when attempting to stop it.

Steps to Reproduce

Run some network request code in the task that might end up timing out.

Context

Background fetch task that executes every 60 minutes, and tries to run in under 20 seconds, stopping itself afterwards to prevent the task from timing out.

Debug logs

java.lang.AssertionError Tried to finish non-existent task with id 2. 
    Assertions.java:72 com.facebook.infer.annotation.Assertions.assertCondition
    HeadlessJsTaskContext.java:164 com.facebook.react.jstasks.HeadlessJsTaskContext.finishTask
    HeadlessJsTaskContext.java:202 com.facebook.react.jstasks.HeadlessJsTaskContext$3.run
    Handler.java:873 android.os.Handler.handleCallback
    Handler.java:99 android.os.Handler.dispatchMessage
    Looper.java:214 android.os.Looper.loop
    ActivityThread.java:6986 android.app.ActivityThread.main
    Method.java:-2 java.lang.reflect.Method.invoke
    RuntimeInit.java:494 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run
    ZygoteInit.java:1445 com.android.internal.os.ZygoteInit.main

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions