Skip to content
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

[Bug]: Program "has exited with code -1073740791 (0xc0000409)" when opening synced realm from two applications at once #2656

Open
polymath74 opened this issue Sep 25, 2021 · 3 comments

Comments

@polymath74
Copy link

What happened?

When I call Realm.GetInstance from my .NET client code normally, it works fine. But if I then run another instance of my application, and call GetInstance, it exits unexpectedly, saying: The program has exited with code -1073740791 (0xc0000409). The Visual Studio debugger does not catch any exceptions or anything, the program just stops, reporting that message to the output.

Best I can find on this exit code is this SO answer which suggests it might be a stack overrun..?

There does seem to be a timing issue involved (maybe with async background threads??) because when I have tried stepping into each instruction, starting from the .GetInstance call, while normally it just exits, on one occasion I actually succeeded in getting a few instructions further - but then it still stopped with the same message a bit later.

(Is this behaviour expected? Is my desired use supported? Should I be doing this another way?)

Repro steps

  1. App.Create(appId)
  2. LogInAsync(apiKey)
  3. Realm.GetInstance(new SyncConfiguration(partition, user))
  4. <leave application running, start another instance of the same application>
  5. App.Create(appId)
  6. LogInAsync(apiKey)
  7. Realm.GetInstance(new SyncConfiguration(partition, user))

Version

Realm 10.5.1 / .NET 5.0

What SDK flavour are you using?

MongoDB Realm (i.e. Sync, auth, functions)

What type of application is this?

WPF

Client OS and version

Windows 10 Pro 21H1 19043.1237 64-bit operating system, x64-based processor Intel(R) Core(TM) i5-6400 CPU @ 2.70GHz 16.0 GB RAM

Code snippets

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        Action action = async () => await ConnectToRealmAsync();
        Dispatcher.BeginInvoke(action, System.Windows.Threading.DispatcherPriority.Background);
    }

    private async Task ConnectToRealmAsync()
    {
        RealmStatus = "Connecting";

        Session.Error += (sender, errorArgs) =>
        {
            Debug.WriteLine("Session Error: " + errorArgs.Exception.Message);
            RealmStatus = errorArgs.Exception.Message;
        };

        try
        {
            var app = Realms.Sync.App.Create(RealmAppId);

            Debug.WriteLine($"app={app}");

            var user = await app.LogInAsync(Credentials.ApiKey(RealmApiKey));

            Debug.WriteLine($"user={user.Id}");
            RealmStatus = "Logged in";

            var config = new SyncConfiguration(user.Id, user);
            var realm = Realm.GetInstance(config); // program exits here before returning to this function, on second instance of application

            Debug.WriteLine($"realm={realm}");
            RealmStatus = "Ready";
        }
        catch (Exception ex)
        {
            Debug.WriteLine("Connection exception: " + ex.Message);
            RealmStatus = ex.Message;
        }

    }

Stacktrace of the exception/crash you're getting

I wish I had a stacktrace!! All I get is:

The program '[6332] RealmTestApp.exe' has exited with code -1073740791 (0xc0000409).

Relevant log output

app=Realms.Sync.App
user=61345920826942f6487d4d57
The program '[6332] RealmTestApp.exe' has exited with code -1073740791 (0xc0000409).
@nirinchev
Copy link
Member

Unfortunately, this is expected behavior - synchronized realms don't multiprocess access.

@polymath74
Copy link
Author

Ah. Ok, so I need to open the realm in separate realm file locations in different processes?

It would be nice if there was a more informative error message for this, rather than a sudden unexpected exit. :)

@nirinchev
Copy link
Member

I agree - that's a native crash that should include an error message but it's not something all platforms surface meaningfully. I'll keep this ticket open and reach out to the core team that is responsible for the sync component to see if we can make this error more actionable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants