-
Type: Improvement
-
Resolution: Won't Fix
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Sync
-
5542
-
Not Needed
This is a slightly different use case than https://github.com/realm/realm-core/issues/5364
All SDK's have a public method for deleting Realms: https://github.com/realm/realm-core/blob/master/src/realm/object-store/shared_realm.hpp#L421.
However, for synchronized Realms this method has race conditions (that in many cases) prevent it from being used correctly. The reason is that the SyncClient keeps a file reference open and there is no way for end-users to know when the SyncClient releases those.
https://github.com/realm/realm-core/blob/master/src/realm/object-store/sync/sync_manager.hpp#L157 is a work-around that work-ish for tests, but isn't really useful for end-users as they might have multiple Realms opened.
Ideally, ObjectStore also exposes a way to fully close all file resources owned by Core/ObjectStore so users can delete the file. If a blocking call is hard to do, even having a closeAsync(), with an event firing on the SyncClient thread would be good enough as we can wrap it in the SDK layer.
Suggested API's:
// Variant 1, if true, will block until any SyncSession is also fully closed. SharedRealm::close(bool terminateSession = true); // Variant 2, will trigger callback when public and SyncSession Realm is closed. SharedRealm::closeAsync(CloseCallback callback);