-
Type: Bug
-
Resolution: Gone away
-
Priority: 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
- First call with {{Realm.open(
Unknown macro: { sync}
)}}
- 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:
- 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().
- 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.
- 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