realm-js
realm-js copied to clipboard
getSyncSession cannot resolve session even though it exsist
How frequently does the bug occur?
Always
Description
I have this piece of code
console.log('getCurrentPartitionValue()', getCurrentPartitionValue());
syncSession = Realm.App.Sync.getSyncSession(
realmApp().currentUser,
getCurrentPartitionValue(),
);
console.log('syncSession', syncSession);
const sessions = Realm.App.Sync.getAllSyncSessions(
realmApp().currentUser,
);
console.log('sessions', sessions);
syncSession = sessions.find(session => {
return session.config.partitionValue === getCurrentPartitionValue();
});
console.log('syncSession', syncSession);
the output is this
LOG getCurrentPartitionValue() 655d5e27fce9035abdbe2654
LOG syncSession null
LOG sessions [{}]
LOG syncSession {}
LOG syncSession {"partitionValue": "655d5e27fce9035abdbe2654", "user": {}}
As you can see, the same partition value and user, used in getSyncSession yield null, yet if I resolve it via getAllSyncSessions, it is exsist
Stacktrace & log output
getCurrentPartitionValue() 655d5e27fce9035abdbe2654
syncSession null
sessions [{}]
syncSession {}
syncSession {"partitionValue": "655d5e27fce9035abdbe2654", "user": {}}
Can you reproduce the bug?
Always
Reproduction Steps
Realm.App.Sync.getSyncSession
Version
^11.10.2
What services are you using?
Both Atlas Device Sync and Atlas App Services
Are you using encryption?
Yes
Platform OS and version(s)
WSL2 on Windows 11
Build environment
Which debugger for React Native: ..
Cocoapods version
➤ PM Bot commented:
Jira ticket: RJS-2785
In our current main branch, we have the following tests: https://github.com/realm/realm-js/blob/main/integration-tests/tests/src/tests/sync/sync-session.ts#L625-L644
I suggest you to upgrade to a recent version (for example v12.6.0), and if the issue is still observed, please let us know.
using 12.6.2
Realm.App.Sync.getSyncSession yield null
while Realm.App.Sync.getAllSyncSessions yield {"weakInternal": {Symbol(Realm.WeakSyncSession.external_pointer): {}}}
@kneth We are also getting the same error in the syncError when we close the app and reopen the app again. But if we logout and login again there is no more error.
const syncConfigWithErrorHandling = { flexible: true, onError: (_session, error) => { console.log(error); }, }; function RealmWithErrorHandling() { return ( <RealmProvider sync={syncConfigWithErrorHandling}> <RestOfApp /> </RealmProvider> ); }
I have upgraded to 12.7.1 latest and the issue is still same. we are getting weakInternal error.
In https://github.com/realm/realm-js/pull/6637 we are reworking how getSyncSession() is implemented due to a refactoring in Realm Core. I hope it will solve the issue.