-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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] Headless Crash Tried to finish non-existent task with id
#46496
Comments
in RodolfoGS/react-native-fix-non-existent-task@6fe3c13 You are calling HeadlessJsTaskContext.getInstance() without checking if reactNativeHost.reactInstanceManager.currentReactContext is available if try this example reactNativeHost.reactInstanceManager.currentReactContext?.let { reactContext ->
val headlessJsTaskContext = HeadlessJsTaskContext.getInstance(reactContext)
// Terminate the headless task if necessary
headlessJsTaskContext.finishTask(123)
} ?: run {
// Handles the case where ReactContext is not yet available
} although the task does not exist, it does not break. |
@mensonones your code works because Try it with my code, or since You could do this: HeadlessJsTaskContext.getInstance(null).finishTask(123) |
Summary: Sometimes a headless task tries to finish, but it doesn’t exist, which causes an exception. No one knows how to reliably reproduce it, as it could be a race condition. However, if you attempt to remove a task that has already been removed, it shouldn’t cause an issue since you're trying to remove something that’s already gone (which is exactly what you want). Fixes: - #46496 - #33883 - #27597 - transistorsoft/react-native-background-fetch#202 - transistorsoft/react-native-background-fetch#369 - transistorsoft/react-native-background-geolocation#2096 - jpush/jpush-react-native#78 ## Stacktrace: ``` Fatal Exception: java.lang.AssertionError: Tried to finish non-existent task with id 28. at com.facebook.infer.annotation.Assertions.assertCondition(Assertions.java:88) at com.facebook.react.jstasks.HeadlessJsTaskContext.finishTask(HeadlessJsTaskContext.java:179) at com.facebook.react.jstasks.HeadlessJsTaskContext$3.run(HeadlessJsTaskContext.java:217) at android.os.Handler.handleCallback(Handler.java:958) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:257) at android.os.Looper.loop(Looper.java:368) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:233) at java.lang.Thread.run(Thread.java:1012) ``` ## Screenshot https://github.com/user-attachments/assets/101f0f53-95c9-40ec-a59d-22d6d474b457 ## Changelog: [ANDROID] [FIXED] - Fix Headless Crash `Tried to finish non-existent task with id` Pull Request resolved: #46497 Test Plan: I created an example where I attempt to remove a task that doesn’t exist. Example: https://github.com/RodolfoGS/react-native-fix-non-existent-task ### How to reproduce using the example above: 1. `git clone [email protected]:RodolfoGS/react-native-fix-non-existent-task.git` 2. `cd react-native-fix-non-existent-task` 3. `npm install` 4. `npm run android` 5. Notice the crash ### Steps to create the example from scratch and reproduce the crash: 1. `npx react-native-community/cli@latest init AwesomeProject` 2. `cd AwesomeProject` 3. Add call to finishTask to reproduce the crash (RodolfoGS/react-native-fix-non-existent-task@6fe3c13) 4. `npm run android` 5. Notice the crash Reviewed By: javache Differential Revision: D62738059 Pulled By: rshest fbshipit-source-id: 3232dc76ba8a069279c2b741d62372537a3f9140
Commit landed b4532ad |
Summary: Sometimes a headless task tries to finish, but it doesn’t exist, which causes an exception. No one knows how to reliably reproduce it, as it could be a race condition. However, if you attempt to remove a task that has already been removed, it shouldn’t cause an issue since you're trying to remove something that’s already gone (which is exactly what you want). Fixes: - #46496 - #33883 - #27597 - transistorsoft/react-native-background-fetch#202 - transistorsoft/react-native-background-fetch#369 - transistorsoft/react-native-background-geolocation#2096 - jpush/jpush-react-native#78 ## Stacktrace: ``` Fatal Exception: java.lang.AssertionError: Tried to finish non-existent task with id 28. at com.facebook.infer.annotation.Assertions.assertCondition(Assertions.java:88) at com.facebook.react.jstasks.HeadlessJsTaskContext.finishTask(HeadlessJsTaskContext.java:179) at com.facebook.react.jstasks.HeadlessJsTaskContext$3.run(HeadlessJsTaskContext.java:217) at android.os.Handler.handleCallback(Handler.java:958) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:257) at android.os.Looper.loop(Looper.java:368) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:233) at java.lang.Thread.run(Thread.java:1012) ``` ## Screenshot https://github.com/user-attachments/assets/101f0f53-95c9-40ec-a59d-22d6d474b457 ## Changelog: [ANDROID] [FIXED] - Fix Headless Crash `Tried to finish non-existent task with id` Pull Request resolved: #46497 Test Plan: I created an example where I attempt to remove a task that doesn’t exist. Example: https://github.com/RodolfoGS/react-native-fix-non-existent-task ### How to reproduce using the example above: 1. `git clone [email protected]:RodolfoGS/react-native-fix-non-existent-task.git` 2. `cd react-native-fix-non-existent-task` 3. `npm install` 4. `npm run android` 5. Notice the crash ### Steps to create the example from scratch and reproduce the crash: 1. `npx react-native-community/cli@latest init AwesomeProject` 2. `cd AwesomeProject` 3. Add call to finishTask to reproduce the crash (RodolfoGS/react-native-fix-non-existent-task@6fe3c13) 4. `npm run android` 5. Notice the crash Reviewed By: javache Differential Revision: D62738059 Pulled By: rshest fbshipit-source-id: 3232dc76ba8a069279c2b741d62372537a3f9140
Summary: Sometimes a headless task tries to finish, but it doesn’t exist, which causes an exception. No one knows how to reliably reproduce it, as it could be a race condition. However, if you attempt to remove a task that has already been removed, it shouldn’t cause an issue since you're trying to remove something that’s already gone (which is exactly what you want). Fixes: - #46496 - #33883 - #27597 - transistorsoft/react-native-background-fetch#202 - transistorsoft/react-native-background-fetch#369 - transistorsoft/react-native-background-geolocation#2096 - jpush/jpush-react-native#78 ## Stacktrace: ``` Fatal Exception: java.lang.AssertionError: Tried to finish non-existent task with id 28. at com.facebook.infer.annotation.Assertions.assertCondition(Assertions.java:88) at com.facebook.react.jstasks.HeadlessJsTaskContext.finishTask(HeadlessJsTaskContext.java:179) at com.facebook.react.jstasks.HeadlessJsTaskContext$3.run(HeadlessJsTaskContext.java:217) at android.os.Handler.handleCallback(Handler.java:958) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:257) at android.os.Looper.loop(Looper.java:368) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:233) at java.lang.Thread.run(Thread.java:1012) ``` ## Screenshot https://github.com/user-attachments/assets/101f0f53-95c9-40ec-a59d-22d6d474b457 ## Changelog: [ANDROID] [FIXED] - Fix Headless Crash `Tried to finish non-existent task with id` Pull Request resolved: #46497 Test Plan: I created an example where I attempt to remove a task that doesn’t exist. Example: https://github.com/RodolfoGS/react-native-fix-non-existent-task ### How to reproduce using the example above: 1. `git clone [email protected]:RodolfoGS/react-native-fix-non-existent-task.git` 2. `cd react-native-fix-non-existent-task` 3. `npm install` 4. `npm run android` 5. Notice the crash ### Steps to create the example from scratch and reproduce the crash: 1. `npx react-native-community/cli@latest init AwesomeProject` 2. `cd AwesomeProject` 3. Add call to finishTask to reproduce the crash (RodolfoGS/react-native-fix-non-existent-task@6fe3c13) 4. `npm run android` 5. Notice the crash Reviewed By: javache Differential Revision: D62738059 Pulled By: rshest fbshipit-source-id: 3232dc76ba8a069279c2b741d62372537a3f9140
Summary: Sometimes a headless task tries to finish, but it doesn’t exist, which causes an exception. No one knows how to reliably reproduce it, as it could be a race condition. However, if you attempt to remove a task that has already been removed, it shouldn’t cause an issue since you're trying to remove something that’s already gone (which is exactly what you want). Fixes: - facebook/react-native#46496 - facebook/react-native#33883 - facebook/react-native#27597 - transistorsoft/react-native-background-fetch#202 - transistorsoft/react-native-background-fetch#369 - transistorsoft/react-native-background-geolocation#2096 - jpush/jpush-react-native#78 ## Stacktrace: ``` Fatal Exception: java.lang.AssertionError: Tried to finish non-existent task with id 28. at com.facebook.infer.annotation.Assertions.assertCondition(Assertions.java:88) at com.facebook.react.jstasks.HeadlessJsTaskContext.finishTask(HeadlessJsTaskContext.java:179) at com.facebook.react.jstasks.HeadlessJsTaskContext$3.run(HeadlessJsTaskContext.java:217) at android.os.Handler.handleCallback(Handler.java:958) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:257) at android.os.Looper.loop(Looper.java:368) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:233) at java.lang.Thread.run(Thread.java:1012) ``` ## Screenshot https://github.com/user-attachments/assets/101f0f53-95c9-40ec-a59d-22d6d474b457 ## Changelog: [ANDROID] [FIXED] - Fix Headless Crash `Tried to finish non-existent task with id` Pull Request resolved: facebook/react-native#46497 Test Plan: I created an example where I attempt to remove a task that doesn’t exist. Example: https://github.com/RodolfoGS/react-native-fix-non-existent-task ### How to reproduce using the example above: 1. `git clone [email protected]:RodolfoGS/react-native-fix-non-existent-task.git` 2. `cd react-native-fix-non-existent-task` 3. `npm install` 4. `npm run android` 5. Notice the crash ### Steps to create the example from scratch and reproduce the crash: 1. `npx react-native-community/cli@latest init AwesomeProject` 2. `cd AwesomeProject` 3. Add call to finishTask to reproduce the crash (RodolfoGS/react-native-fix-non-existent-task@6fe3c13) 4. `npm run android` 5. Notice the crash Reviewed By: javache Differential Revision: D62738059 Pulled By: rshest fbshipit-source-id: 3232dc76ba8a069279c2b741d62372537a3f9140
Description
Sometimes a headless task tries to finish, but it doesn’t exist, which causes an exception.
No one knows how to reliably reproduce it, as it could be a race condition. However, if you attempt to remove a task that has already been removed, it shouldn’t cause an issue since you're trying to remove something that’s already gone (which is exactly what you want).
Related:
Pull Request
I created a PR to fix it.
PR: #46497
Steps to reproduce
I created an example where I attempt to remove a task that doesn’t exist.
Example: https://github.com/RodolfoGS/react-native-fix-non-existent-task
How to reproduce using the example above:
git clone [email protected]:RodolfoGS/react-native-fix-non-existent-task.git
cd react-native-fix-non-existent-task
npm install
npm run android
Steps to create the example from scratch and reproduce the crash:
npx @react-native-community/cli@latest init AwesomeProject
cd AwesomeProject
npm run android
React Native Version
0.75.3
Affected Platforms
Runtime - Android
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://github.com/RodolfoGS/react-native-fix-non-existent-task
Screenshots and Videos
Screen.Recording.2024-09-14.at.12.56.27.PM.mov
The text was updated successfully, but these errors were encountered: