Uploaded image for project: 'Realm Core'
  1. Realm Core
  2. RCORE-468

Multiprocess issue on windows

      On Windows, writing from multiple processes while simultaneously listening for notifications causes something to lock up preventing the Realm from refreshing/delivering notifications.

      Here's a simple app that reproduces the issue after 3-4 instances of it are run:

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      using System;
      using System.Linq;
      using System.Threading.Tasks;
      using Nito.AsyncEx;
      using Realms;
      
      namespace SimpleRealmWriter
      {
          internal class Program
          {
              private const string RealmLocation = "C:\\Work\\example.realm";
      
              private static void Main(string[] args)
              {
                  AsyncContext.Run(async () =>
                  {
                      var realm = Realm.GetInstance(RealmLocation);
                      var counter = realm.All<MyCounter>().FirstOrDefault();
                      if (counter == null)
                      {
                          counter = new MyCounter();
                          realm.Write(() => realm.Add(counter));
                      }
                      counter.PropertyChanged += (s, e) =>
                      {
                          Console.WriteLine($"Counter's {e.PropertyName} changed: {counter.Value}");
                      };
      
                      while (true)
                      {
                          await Task.Delay(1000);
                          var tsr = ThreadSafeReference.Create(counter);
                          await Task.Run(() =>
                          {
                              using var bgRealm = Realm.GetInstance(RealmLocation);
                              var bgCounter = bgRealm.ResolveReference(tsr);
                              bgRealm.Write(() =>
                              {
                                  bgCounter.Value++;
                              });
                          });
      
                          realm.Refresh(); // Locks up here
      
                          Console.WriteLine($"Counter: {counter.Value}");
                      }
                  });
              }
          }
      
          internal class MyCounter : RealmObject
          {
              public int Value { get; set; }
          }
      }
      

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: