react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Tried to finish non-existent task with id x
Your Environment
- Plugin version: 4.16.1
- Platform: Android
- OS version: Android 5.1.1 to Android 14
- Device manufacturer / model: Many devices, mainly Samsung Galaxy Tab Active3, Google Pixel 7, Samsung Galaxy S22
- React Native version (
react-native -v): 0.73.0 - Plugin config
const config = {
desiredAccuracy: Platform.select({
ios: BackgroundGeolocation.DESIRED_ACCURACY_NAVIGATION,
android: BackgroundGeolocation.DESIRED_ACCURACY_HIGH
}),
distanceFilter: 5,
elasticityMultiplier: 15,
allowIdenticalLocations: false,
stopTimeout: 2,
speedJumpFilter: 75,
maxDaysToPersist: 2,
stopOnTerminate: false,
enableHeadless: true,
startOnBoot: true,
forceReloadOnBoot: true,
foregroundService: true,
autoSync: false,
logMaxDays: 2,
locationAuthorizationRequest: 'Always',
reset: false,
...
}
Expected Behavior
Registering a headless task should run the task in the background, and this handler should continue running without errors
Actual Behavior
Registering a headless task works as expected, with the task performing async writes to a file. However on a number of different devices in production I have noticed the following error on Sentry: Tried to finish non-existent task with id 1, where this number ranges between 1 and 5. This error also appears as a crash in Google Play Console, with the following stack trace:
Exception java.lang.AssertionError: Tried to finish non-existent task with id 1.
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:938)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loopOnce (Looper.java:226)
at android.os.Looper.loop (Looper.java:313)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run (MessageQueueThreadImpl.java:234)
at java.lang.Thread.run (Thread.java:920)
I have not been able to reproduce this locally, however Google Play console reports a large percentage of android users being affected, and this is affecting the "bad behaviour". I do not have any issues in iOS.
Steps to Reproduce
await BackgroundGeolocation.ready(config)await BackgroundGeolocation.setConfig(config)BackgroundGeolocation.registerHeadlessTask(async (event) => {...})
Context
react-native-background-geolocation is the only headless task that is registered within the app, hence my surmising that this is the culprit library.
Debug logs
Logs
PASTE_YOUR_LOGS_HERE
This issue is stale because it has been open for 30 days with no activity.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.