question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

6reactions
RodolfoGScommented, Apr 14, 2021

I have the same issue:

Fatal Exception: java.lang.AssertionError: Tried to finish non-existent task with id 2.
       at com.facebook.infer.annotation.Assertions.assertCondition(Assertions.java:72)
       at com.facebook.react.jstasks.HeadlessJsTaskContext.finishTask(HeadlessJsTaskContext.java:173)
       at com.facebook.react.jstasks.HeadlessJsTaskContext$3.run(HeadlessJsTaskContext.java:211)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:205)
       at android.app.ActivityThread.main(ActivityThread.java:6991)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:884)
0reactions
pedrolopes10commented, Jun 9, 2022

Thanks @cristianoccazinsp. I also think it’s not related to this library as I’ve done a deploy without it and the issue persisted. I also use react native firebase messaging that uses HeadlessTasks but couldn’t reach any conclusion. So any suggestion is welcome!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Crash - Tried to finish non-existent task with id 2
Just received a random Android crash from the crash reporting tool. I know the app's only headless task with a timeout value comes...
Read more >
Android Fatal signal 11 (SIGSEGV) at 0x636f7d89 (code=1 ...
Your not getting this fatal-exception due to java.security,MessageDigest or any thread. It may not be the exact location where memory is being corrupted....
Read more >
Crashes | Android Developers
An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java...
Read more >
Unity Android build crash when using ARM64 with IL2CPP
Adding android:allowBackup="false" tools:replace="android:allowBackup" to the Android Manifest seemed to fix it for us. Sounds like the same ...
Read more >
Android - Countly
The Countly SDK for Android has the ability to collect crash reports, ... countly { // required by both tasks server "https://try.count.ly" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found