Closed geosebas closed 1 year ago
@geosebas You don't need to use a different config
when you are in the same process. Configuration.disconnectedSync
is for opening a synchronized realm without connecting to the server and start syncing. A benefit is that you can open the same synchronized realm in multiple processes, but if you have just one process you should just use Configuration.flexibleSync
for all realms. Isolates are not true processes and realm-core will share the sync session across isolates at the native layer.
In general DisconnectedSyncConfiguration
is mostly intended for less common use-cases, such as writing your own version of Realm Studio, working with multiprocess systems such as Electron, or as in the time_track sample, where the different cli commands use Configuration.disconnectedSync
to quickly open, change, and close a realm, that is synced in the background by a deamon process.
To be a bit more precise
FlexibleSyncConfiguration
at a time,DisconnectedSyncConfiguration
, even if already opened by another process using a FlexibleSyncConfiguration
.Hi @nielsenko.
Thanks for the answer, but I'm not sure to understand something. You first say :
but if you have just one process you should just use Configuration.flexibleSync for all realms.
and then :
When opening a synchronized realm, only one can open it with a FlexibleSyncConfiguration at a time,
Of course I directly tried to use Configuration.flexibleSync
just before writing this message but I got the same error.
So the big question is, how can I access my realm from different isolate ?
I forgot a process in there, have edited the answer.
You should be able to open the realm again in another isolate in the same process, as long as you use the same config type, ie. FlexibleSyncConfiguration
. That said, I tried to create an example of how to do it, and I hit another issue:
..b91b8fd9d77bf/default.realm' already opened with different sync user.)
despite using the exact same user 🤔
I think you have hit a bug here. Will get back when I know more.
I forgot a process in there, have edited the answer.
Much clearer now :D
That said, I tried to create an example of how to do it, and I hit another issue:
I got this error too ! This is weird because when I print this in both isolate, I got the same result :
debugPrint(currentUser.id);
debugPrint(currentUser.identities[0].id);
@geosebas I believe this is an issue in realm-core caused by a comparison of std::shared_ptr<SyncUser>
s instead of SyncUser
s. I have opened a PR https://github.com/realm/realm-core/pull/6087. Let us see what they come back with.
Unlike most SDK we don't use native caching of app instances in realm-dart. This is because they cause trouble when used between different isolates (you may remember the hot-restart crash of 0.3.2+beta). I think that is what causes the current check to be defeated.
The PR fixes it for me, in my test, and passes all existing tests in realm-dart, but let us see how it fares in core.
Nice I will wait for the fix :)
Thanks for your help and the quick answer !
Hi @nielsenko ,
Sorry to bother you but do you have any news about this ? Do you know if the fix will be included in the next release ?
On another point, do you know how the SDK handle the call to the manual reset handler when the realm is opened in more than one isolate ? What will happen if more than one clientResetError.resetRealm();
is called ?
Have a nice day :)
I got a bit side-tracked, I will return to this now.
Sorry I pressed 'enter' to soon so I edited my previous message ^^
I expect the fix to be included in the next release, but no promises. The second call to clientResetError.resetRealm()
will do nothing.
I have opened a PR https://github.com/realm/realm-core/pull/6117 to surface the result. Once that land I will change resetRealm
to return bool indicating if resetRealm
ran or not.
Nice thanks a lot :)
Hello there, just wanted to know if you have an idea about when will we have the next release and if this fix will be in the next release.
Sorry to bother you just for that, but I will release soon to production my app, and I don't like the dirty workarround I did for this, so if I can have the fix before going in production, it will be perfect for me :)
And not to bother you again with this type of question, do you have any channels where we can have theses type of info ? Like a discord or slack where we will know when you release, or if you're hold back or anything ? That would be great !
@geosebas This is dependent on a new release of realm-core. We have been hesitant to roll a release, since there was a number of issues with the latest realm-core version (13+), after a major refactoring of how frozen objects affects version pinning. These are slowly and steadily being worked through.
I cannot give dates, but we are getting close.
import 'dart:async';
import 'dart:isolate';
import 'package:realm_dart/realm.dart';
part 'isolate_test.g.dart';
@RealmModel()
class _Stuff {
late int no;
@override
String toString() => 'Stuff($no)';
}
// Note this is per isolate!
final realm = Realm(Configuration.inMemory([Stuff.schema]));
StreamSubscription monitorChanges(String isolateTag) {
return realm.all<Stuff>().changes.listen((event) {
print('$isolateTag: ${event.inserted}');
});
}
extension on StreamSubscription {
Future<void> cancelIn(int seconds) async {
await Future.delayed(Duration(seconds: seconds));
await cancel();
}
}
Future<void> main(List<String> arguments) async {
final s = monitorChanges('root');
await Isolate.spawn((message) async {
final s = monitorChanges('spawned');
realm.write(() => realm.addAll([
Stuff(1),
Stuff(2),
]));
await s.cancelIn(1);
}, null);
await s.cancelIn(1);
for (final stuff in realm.all<Stuff>()) {
print(stuff);
}
Realm.shutdown();
}
Outputs:
root: []
spawned: []
root: [0, 1]
spawned: [0, 1]
Stuff(1)
Stuff(2)
Exited.
What happened?
Hello,
I'm trying to follow the doc from here : https://www.mongodb.com/docs/realm/sdk/flutter/sync/sync-multiple-processes/
But as soon as I open the disconnected realm, I got this error :
My goal is to create complex data from multiple collection, so I need to do this in another Isolate so I don't freeze the UI. To do that I use the
compute
function from flutter foundation.Here some of my code :
Synced realm :
DisconnectedRealm :
Flutter doctor :
Repro steps
Version
0.8.0rc
What Realm SDK flavor are you using?
MongoDB Atlas (i.e. Sync, auth, functions)
What type of application is this?
Flutter Application
Client OS and version
Android 33.0
Code snippets
No response
Stacktrace of the exception/crash you're getting
Relevant log output
No response