Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android HeadlessJS Crash - Tried to finish non-existent task with id #27597

Closed
cristianoccazinsp opened this issue Dec 24, 2019 · 5 comments
Closed
Labels
Bug Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@cristianoccazinsp
Copy link
Contributor

Just received a random Android crash from the crash reporting tool. I haven't been able to reproduce it, but the headless task runs every 60 minutes and is intended to finish before the 30s timeout it is given. The crash happened from a headless task that didn't run with the app previously initialized (with an UI / main activity). Crash

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

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

From the above I can't really tell if the task timed out and it failed to be notified, or if it finished on time, but the timeout also fired (a race condition between the is running check and the actual finish call?) causing the crash. For me this assertion seems a bit to aggressive, and it should be just a warning rather than an app crash.

React Native version:

System:
    OS: macOS Mojave 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
    Memory: 221.69 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.15.3 - /usr/local/bin/node
    npm: 6.13.4 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
    Android SDK:
      API Levels: 28, 29
      Build Tools: 28.0.3, 29.0.2
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5522156
    Xcode: 11.2.1/11B53 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.12.0 => 16.12.0 
    react-native: 0.61.5 => 0.61.5 
  npmGlobalPackages:
    create-react-native-app: 2.0.2
    create-react-native-module: 0.10.2
    react-native-cli: 2.0.1

Steps To Reproduce

  1. Create a headless js task with 30 seconds timeout or so. The JS code should not exceed the timeout.
  2. Run the task from an alarm manager, or something that allows you to run it periodically (e.g., react-native-background-fetch)
  3. Observe the crash. Note, this crash is quite random, and happened once in a 30d time period of about 350 android devices.
@react-native-bot react-native-bot added the Platform: Android Android applications. label Dec 24, 2019
@stale
Copy link

stale bot commented Mar 23, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 23, 2020
@cristianoccazinsp
Copy link
Contributor Author

cristianoccazinsp commented Mar 23, 2020 via email

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 23, 2020
@julianD77
Copy link

julianD77 commented Mar 30, 2020

We are also seeing this issue affect our App: 0.61.5 across a range of Android versions.

We haven't yet investigated it fully but I wonder if it might be related to the power settings on Android devices and some of the issues which are detailed here: https://dontkillmyapp.com/

Or as you say @cristianoccazinsp a race condition that is very hard to reproduce.

@stale
Copy link

stale bot commented Jun 28, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jun 28, 2020
@stale
Copy link

stale bot commented Jul 5, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Jul 5, 2020
@facebook facebook locked as resolved and limited conversation to collaborators Jul 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

3 participants