Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-2719

"Realm at path already opened with different sync user" upon reopening with identical configuration

      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

      Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: