realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.61k stars 558 forks source link

getSyncSession cannot resolve session even though it exsist #6582

Open deckyfx opened 3 weeks ago

deckyfx commented 3 weeks ago

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

-

sync-by-unito[bot] commented 3 weeks ago

➤ PM Bot commented:

Jira ticket: RJS-2785

kneth commented 3 weeks ago

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.

deckyfx commented 2 weeks ago

using 12.6.2 Realm.App.Sync.getSyncSession yield null while Realm.App.Sync.getAllSyncSessions yield {"weakInternal": {Symbol(Realm.WeakSyncSession.external_pointer): {}}}

vatsal-gadhiya-searce commented 6 days ago

@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 (

); }

vatsal-gadhiya-searce commented 5 days ago

I have upgraded to 12.7.1 latest and the issue is still same. we are getting weakInternal error.

kneth commented 3 days ago

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.