Run Mapeo Core as a long-running background task #819
gmaclennan
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
On Android, the Node process is started using a
Thread
. When the user puts the app in the background, Android can terminate this thread. The criteria for this is unclear to me, but it seems to be that actively listening on a port (e.g. for a server) will cause Android to terminate the thread when the app is in the background. When the app comes back into the foreground, we currently have no logic to restart the Node thread, so the app ceases working. For this reason we have a lot of logic that listens for the app being moved into the background and stops all servers from listening.This background behaviour is complicated when it comes to syncing. Syncing with other devices can take several minutes, and it is currently not safe to terminate sync before it finishes (because we do not properly support sparse hypercores). To work around this we currently check for active syncs when the app goes into the background, then allow the sync to continue for 9 minutes, in the hope that this is within a 10 minute threshold for Android before the thread is terminated.
One potential solution to this is to run the Node thread as a background process, as outlined here: https://developer.android.com/guide/background
This would require modifying the
nodejs-mobile-react-native
code, or writing our own Java module to initialize the Node thread on app startup. I am unclear how IPC communication will work if we run the Node thread with this technique. Also, this will require different code for iOS, which is much stricter about background processing.This change would potentially simplify our sync code, allowing sync and p2p upgrade checks and downloads to continue even if the user switches to a different app.
Beta Was this translation helpful? Give feedback.
All reactions