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

Cannot change sync session config between calls to Realm.open

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None

      Goals

      I want to be able to call {{Realm.open(

      { ... }

      )}} with two different values for the sync.validate_ssl configuration.

      Specifically I want to be able to

      1. First call with {{Realm.open(
        Unknown macro: { sync}

        )}}

      2. Ff the connection fails (I can detect that when the the sync's error callback is fired) I want to re-open the realm with a different configuration {{Realm.open(
        Unknown macro: { sync}

        )}}.

      Expected Results

      If opening a synchronized Realm on ROS that uses an untrusted certificate I would expect the first call to fail and the second call to succeed.

      Actual Results

      The second call to Realm.open never resolves (and it actually never gets rejected either).

      I suspect that the underlying implementation caches the configuration - probably because its used to open a sync session which is reused. But that is an unexpected and undocumented side-effect from calling Realm.open.

      If this is the case - a couple of alternative ways of achieving the goal comes to mind:

      1. The Session object used by Realm JS could be invalidated, forgotten (and perhaps closed) - so the next call to Realm.open would instantiate and open a new session. Perhaps by calling Realm.closeSession(), Realm.invalidateSession() or Realm.forgetSession().
      2. The call to Realm.open might take a session as an argument instead of the sync config parameters that gets passed to initialize the session.
      3. Perhaps opening a Realm should be a function on a session rather than the global Realm object and Realm.open just be a shorthand to open with the default session.

      Steps to Reproduce & Code Sample

      Start ROS with a self-signed certificate and run the following .js script using node:

      async function run() {
        const user = await Realm.Sync.User.login('https://localhost:9443/', 'realm-admin', '');
        const url = 'realms://localhost:9443/__admin';
        // First attempt
        try {
          await Realm.open({
            sync: {
              url,
              user,
              validate_ssl: true,
            }
          });
        } catch (err) {
          console.log(`Expected failure: ${err.message}`);
        }
        // Second attempt
        await Realm.open({
          sync: {
            url,
            user,
            validate_ssl: false,
          }
        });
      }
      
      run();
      

      Version of Realm and Tooling

      • Realm JS SDK Version: 2.0.2
      • Node or React Native: Electron
      • Client OS & Version: Mac

            Assignee:
            kraen.hansen@mongodb.com Kræn Hansen
            Reporter:
            kraen.hansen@mongodb.com Kræn Hansen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: