-
Type:
Bug
-
Resolution: Works as Designed
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
How frequently does the bug occur?
Always
Description
I have a React Native app with Realm and Device Sync configured as per the starter docs.
I am trying to use Expo TaskManager to run a background task where location data is written to Realm.
The background task runs in global context, outside of React, so I cannot access use hooks to access the Realm context.
So I attempt to connect to the Realm with Realm.open(), using identical configuration and the app.currentUser (anonymous auth) but I get this error:
TaskManager: Task "LOCATION_TRACK" failed: [Error: Realm at path '/data/data/[redacted]/files/mongodb-realm/[redacted]/[redacted ID]/flx_sync_default.realm' already opened with different sync user.]
I understood from this comment that I should be able to open the Realm twice successfully without error:
https://github.com/realm/realm-js/issues/6273#issuecomment-1869013164
Stacktrace & log output
TaskManager: Task "LOCATION_TRACK" failed: [Error: Realm at path '/data/data/[redacted]/files/mongodb-realm/[redacted]/[redacted ID]/flx_sync_default.realm' already opened with different sync user.]
Can you reproduce the bug?
Always
Reproduction Steps
Create an expo app with Realm and Device Sync configured as per the starter docs.
Realm works correctly inside React using hooks.
Attempt to open the Realm outside the React context, using the same config, and get the error.
const app = new Realm.App({ id: ATLAS_APP_ID }); const realm = await Realm.open({ schema: [LocationLog], sync: { flexible: true, user: app.currentUser, }, });
Version
^12.6.0
What services are you using?
Atlas Device Sync
Are you using encryption?
No
Platform OS and version(s)
Windows
Build environment
No response
Cocoapods version
No response