-
Notifications
You must be signed in to change notification settings - Fork 426
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
Headless Tasks on react-native 0.76.3 #2225
Comments
Are you sure this statement is true?
I think when the javascript async task resolves its Promise, that finishTask is called I see calls to this from AppRegistry.js's code through the CodeGen-d imagine-it-exists layer to here But, prove me wrong :-) (I could easily be wrong here, I'm reading this code first time) |
Thanks, that file is new to me; I'll have a close look. It seems to me that pre-new-arch headless-tasks used to stop after executing the last line of code in the function -- you had to be careful to here's a simple headless-task that My headless-tasks are configured to have a const bgGeoHeadlessTask = async (event) => {
console.log('[BGGeoHeadlessTask]');
doWorkCounter = 0;
// Perform a weird action (for testing) with an interval timer and .startBackgroundTask.
const bgTaskId = await BackgroundGeolocation.startBackgroundTask();
// Print * tick * to log every second.
const timer = setInterval(() => {
`[BGGeoHeadlessTask][doWork] * tick ${++doWorkCounter} *`);
}, 1000);
// After a reallllllly long time, stop the interval and stop our background-task.
setTimeout(() => {
clearInterval(timer);
BackgroundGeolocation.stopBackgroundTask(bgTaskId);
}, 2000000); // <-- keep counting seconds for a loooong time.
} .
.
.
12-05 18:38:50.611 8126 8164 I ReactNativeJS: [BGGeoHeadlessTask][doWork] * tick 115 *
12-05 18:38:51.620 8126 8164 I ReactNativeJS: [BGGeoHeadlessTask][doWork] * tick 116 *
12-05 18:38:52.625 8126 8164 I ReactNativeJS: [BGGeoHeadlessTask][doWork] * tick 117 *
12-05 18:38:53.632 8126 8164 I ReactNativeJS: [BGGeoHeadlessTask][doWork] * tick 118 *
12-05 18:38:54.641 8126 8164 I ReactNativeJS: [BGGeoHeadlessTask][doWork] * tick 119 *
12-05 18:38:54.729 8126 8126 D TSLocationManager: [onHeadlessJsTaskFinish] taskId: 1
|
This should be where the headless JS-task is executed. I wonder what this |
I think it is the missing link between the javascript and the direct binding to the native module(s), and that as the Promise on JS side resolves, it calls the native TurboModule's listener which is this support object, |
Oh crap...I put some
Something I'm doing (or not doing) is causing that to be missing. I wonder what's the signal that causes that to exist? taskProvider()(data)
.then(() => {
console.log('*** taskProvider then()', NativeHeadlessJsTaskSupport);
if (NativeHeadlessJsTaskSupport) {
console.log('*** IN IF');
NativeHeadlessJsTaskSupport.notifyTaskFinished(taskId);
} else {
console.log('*** IN ELSE'); // <--- Always ending up here.
}
}) |
Out of current spelunking time box on this but near as I can tell by clicking around the symbol search on github UI
So why is the TurboModuleRegistry .get here not returning one? Especially when it seems to be peppered in to all the correct spots in the list of basic packages? Very curious |
I changed to
|
That's expected based on your observed behavior but unexpected based on reasonable expectations 😆 - why...what, in your use case + in the React init process is not happening such that the TurboModuleRegistry isn't populated with that or is not returning that object? |
Damn, I'll have to keep my wrapper until I figure out how these new TurboModules are created and composed. Fortunately, I've always used a wrapper around Once I figure out what's wrong, I can simply remove it all with no change to my API and nobody will ever know. Thanks for the tips! |
Wish my tips led to effective + understandable resolution. All this stuff is vital to notifee and react-native-firebase so I'm trying my best to understand it as well (vs just expecting it to work...). I think we're both about to learn something then, just don't know what. And I need to do some more testing on the RNFB/Notifee side to make sure all the things you've already mentioned are being done correctly, I think it's a list of about 5-6 things right now and I bet I'm handling 1-2 correctly. Adding to that list of skills either way ("running react-native built from source" is on there now, "command-line trigger of headlessJS" is on there, etc) |
can i get such errors because of this topic?
found it in sentry logs |
This issue is stale because it has been open for 30 days with no activity. |
Found any solution to this? |
We're facing this issue as well. Created an issue to request assistance. |
Facing same issue with react-native 0.73.9 and "react-native-background-geolocation": "4.18.3". |
@mikehardy related to facebook/react-native#48124
I had a good look at the code involved with RN headless-tasks and added a note in my own wrapper
RN headless-tasks have no mechanism for the Javascript to signal completion of their tasks: you can either configure a timeout for your tasks (letting each task time-out, scheduling a timeout
Runnable
or provide no timeout at all, which will cause a memory leak in RN'sHeadlessJsContext
in these two collectionsI prefer not to execute and -- let time-out -- a
Runnable
for each and every invoked headless-task.Without providing a timeout for your headless-tasks, those collections in
HeadlessJsTaskContext
will continue to grow and never be cleared. The only place where elements seem to be removed from those two of its collections (mActiveTasks
andmActiveTaskConfigs
) is infinishTask
.finishTask
is called only from timeouts.A major problem I had was that you only know the RN
taskid
until afterstartTask
has already executed, preventing me from being able to transmit that into the user's Javascript headlessTask.So I had to make my own wrapper around RN tasks and manage my own collection to keep a
taskId
mapping between my tasks and RN's.The whole purpose of my headless-task runner is to be able to use a javascript method
.finishHeadlessTask(taskId)
for users to signal completion of their work.What would be nice is if RN provided an internal way to signal completion of headless-tasks.
The text was updated successfully, but these errors were encountered: