-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.NET process crashes when accessing a Realm that is also open in Studio #3437
Comments
Hi!
Neither one of these are 100% consistent but happens fairly often.
I have attached my local db (from the test app that also includes some additional empty collections). |
The test app crashes in DEBUG builds, with/without a debugger attached. That may be a clue. |
Thanks for getting back - I have a fix for the history type issue: realm/realm-studio#1594 but I'm more interested in the app crashing - can you clarify the sequence of actions you take to make it crash in debug? Notably, do you first open the realm file in Studio, then run the app? Do you add some data/does some data get synchronized from your App Services application or does it crash on startup? I've tried a bunch of permutations I could think of but haven't been able to get it to crash. |
I first ran the test app to create a local realm db/file. Running the app in Release mode works fine, switching back to debug mode again fails intermittently and so on. It still fails intermittently after closing the file in Realm Studio and reopening again (in Studio) + then running the app, debug build. |
I have tried it out on two separate computers, both with similar result (it is not 100% consistent so it seems to be a timing bug of sorts). Both running Win 11 and the same VS + Realm Studio version. |
And just to be clear - once you close the realm file in Studio, your app works just fine in debug mode again? I'll try to play a bit more with this and see if I can get it to reproduce. |
I was able to reproduce this with a native debugger attached - seems to be due to
I'll report back once we have more info, but this is likely a bug in the Core database/sync client, so it may take a bit longer to resolve. |
Correct! However, I am stupid regarding debug/release - I did not switch .realm file in Realm Studio. This is an example output - the first run it worked fine, the next run failed: C:\Users\jakob\Downloads\realm-test\RealmStudioCrash\bin\Release\net7.0> .\RealmStudioCrash.exe |
@jakobmollas we were able to narrow down the root causes of the issue you're seeing and I filed bug reports for the Core team to track and fix them. In the meantime, you can add the following (fairly hacky) code to your app that should allow you to keep Studio open while you debug/terminate your app: var config = new FlexibleSyncConfiguration(...);
#if DEBUG
var lockFilePath = config.DatabasePath + ".lock";
if (File.Exists(lockFilePath))
{
using var stream = new FileStream(lockFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
stream.Seek(40, SeekOrigin.Begin);
stream.WriteByte(0);
stream.Flush();
}
#endif
var realm = Realm.GetInstance(config); The root problem is that we're using a file called What the hacky workaround does is it opens the lock file and sets the sync agent flag to 0 before opening the Realm file. Since this is quite unsafe, we recommend you only do it in debug mode and only if you're certain there's only ever one process accessing the Realm file (i.e. you're not running multiple instances of your app at the same time). You should also only ever do it once when your app starts and before you open the Realm file. I realize it's less than ideal and we'll try to prioritize fixing the Core bugs, but it should offer you a temporary path forward until we're ready. I'll close this issue now because the fixes are tracked in the linked tickets, but feel free to comment here or in the linked tickets if you have questions or concerns. |
Ah, ok I understand the dilemma here. We can live with the workaround for a while but yeah, fixing the underlying issue would be really good. |
A user has reported that using .NET 11.4.0 and Studio 14.0.3, they get crashes when opening a synchronized Realm in both .NET app and Studio. Platform they're using is Windows. See slack thread for more details.
The text was updated successfully, but these errors were encountered: