realm / realm-object-server

Tracking of issues related to the Realm Object Server and other general issues not related to the specific SDK's
https://realm.io
293 stars 42 forks source link

Bug when local Realm is open in Realm Studio #345

Closed kentfonager closed 6 years ago

kentfonager commented 6 years ago

Goals

When developing on a .Net Core application, I open a local Realm in this way:

var realm = Realm.GetInstance(new RealmConfiguration("appcore.realm") { 
    ShouldDeleteIfMigrationNeeded = true,
});

I use the "ShouldDeleteIfMigrationNeeded" flag, as this project is under development and models changes very often.

I like to have the same "appcore.realm" local Realm open in Realm Studio at the same time, to kinda "visualize" the content of the Realm. But when I make a change in one of the models in the application and Realm Studio is open at the same time, something goes wrong and I end up with a non existing "appcore.realm" file. Only the "appcore.realm.lock" is still there.

Expected Results

I would expect the local Realm to be deleted and created again with the new models, even though Realm Studio has the "old" Realm open. it should be able to handle that.

Actual Results

The local Realm is deleted, but my applications gets an RealmFileNotFoundException exception, when it tries to open the local Realm. So something goes wrong, when Realm tries to create the new local Realm. Maybe because Realm Studio in some way, still holds a reference to the file?

Realms.Exceptions.RealmFileNotFoundException: Directory at path '/Users/kentfonager/appcore.realm' does not exist.
   at Realms.NativeException.ThrowIfNecessary(Func`2 overrider) in /Users/realm/workspace/realm_realm-dotnet_PR-1633/Realm/Realm/Native/NativeException.cs:line 57
   at Realms.SharedRealmHandle.Open(Configuration configuration, RealmSchema schema, Byte[] encryptionKey) in /Users/realm/workspace/realm_realm-dotnet_PR-1633/Realm/Realm/Handles/SharedRealmHandle.cs:line 151
   at Realms.RealmConfiguration.CreateRealm(RealmSchema schema) in /Users/realm/workspace/realm_realm-dotnet_PR-1633/Realm/Realm/RealmConfiguration.cs:line 153
   at SyncServerCore.RealmHelper.DefaultRealm() in /Users/kentfonager/Documents/place2book/SyncServerCore/SyncServerCore/Helpers/RealmHelper.cs:line 15
   at SyncServerCore.Repository.<Init>d__12.MoveNext() in /Users/kentfonager/Documents/place2book/SyncServerCore/SyncServerCore/Helpers/Repository.cs:line 34
   at SyncServerCore.Repository.<Init>d__12.MoveNext() in /Users/kentfonager/Documents/place2book/SyncServerCore/SyncServerCore/Helpers/Repository.cs:line 63
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

Steps to Reproduce

Please use my simple test repo and run the solution with Visual Studio for Mac. https://github.com/kentfonager/realmmigration

  1. First run the code and make sure a local file named "test.realm" will be created.
  2. Open that local Realm with Realm Studio and keep it open
  3. Now change the "/Models/TestModel.cs" and either add or remove a property of the class
  4. Run the code again and a exception should be thrown, because the file could not be opened

Code Sample

Version of Realm and Tooling

Logs

systemctl status realm-object-server.service Paste output here
sudo journalctl -u realm-object-server.service Paste output here
cat /var/log/realm-object-server.log Paste output here
bmunkholm commented 6 years ago

@kentfonager Did you check to see that it does work when Studio is not having the file open at the same time?

kentfonager commented 6 years ago

I only experience this problem, when Studio is open. Otherwise the database is deleted and recreated.

Have you been able to reproduce with my repo?

kentfonager commented 6 years ago

Problem still exists in 1.18.6. Have you been able to reproduce @bmunkholm ?

bmunkholm commented 6 years ago

Hi Kent, Sorry didn't catch this was reopened. It's expected that you can't have the file open from an application (Studio), delete the file while Studio still has it open and expect that to work. Sorry we can't help with that one.