realm-js icon indicating copy to clipboard operation
realm-js copied to clipboard

getSyncSession cannot resolve session even though it exsist

Open deckyfx opened this issue 1 year ago • 6 comments

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

deckyfx avatar Apr 03 '24 09:04 deckyfx

➤ PM Bot commented:

Jira ticket: RJS-2785

sync-by-unito[bot] avatar Apr 03 '24 09:04 sync-by-unito[bot]

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.

kneth avatar Apr 04 '24 12:04 kneth

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

deckyfx avatar Apr 15 '24 02:04 deckyfx

@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> ); }

vatsal-gadhiya-searce avatar Apr 23 '24 12:04 vatsal-gadhiya-searce

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

vatsal-gadhiya-searce avatar Apr 24 '24 09:04 vatsal-gadhiya-searce

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.

kneth avatar Apr 26 '24 14:04 kneth