"The specified table name is already in use" on concurrent Realm.GetInstance calls

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None

      What happened?

      Concurrent Realm.GetInstance calls fail if the realm file doesn't exist yet.
      See repro steps: "t1" fails - t2, t3 and t4 succeed
      Not reproducible with Realm 10.9.0!

      Repro steps

      execute NUnit test (also reproducible with Xamarin Android app):

      [Test]
          public async Task Test_ParallelOpen()
          {
              try
              {
                  var t1 = Task.Run(() =>
                  {
                      using var realm = Realm.GetInstance(Path.Combine(_baseDirectory, "foobar.realm"));
                  });
      
                  var t2 = Task.Run(() =>
                  {
                      using var realm = Realm.GetInstance(Path.Combine(_baseDirectory, "foobar.realm"));
                  });
      
                  await Task.WhenAll(t1, t2);
              }
              catch (Exception)
              {
                  var t3 = Task.Run(() =>
                  {
                      using var realm = Realm.GetInstance(Path.Combine(_baseDirectory, "foobar.realm"));
                  });
      
                  var t4 = Task.Run(() =>
                  {
                      using var realm = Realm.GetInstance(Path.Combine(_baseDirectory, "foobar.realm"));
                  });
      
                  await Task.WhenAll(t3, t4);
      
                  throw;
              }
          }
      

      Version

      10.21.1

      What Atlas Services are you using?

      Local Database only

      What type of application is this?

      Console/Server

      Client OS and version

      Mac OS 12.6.5

      Code snippets

      No response

      Stacktrace of the exception/crash you're getting

      Unable to find source-code formatter for language: shell. 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
      Starting test execution, please wait...
      A total of 1 test files matched the specified pattern.
        Failed Test_ParallelOpen [440 ms]
        Error Message:
         System.ArgumentException : The specified table name is already in use
        Stack Trace:
           at Realms.NativeException.ThrowIfNecessary()
         at Realms.SharedRealmHandle.Open(Configuration configuration, RealmSchema schema, Byte[] encryptionKey)
         at Realms.RealmConfiguration.CreateHandle(RealmSchema schema)
         at Realms.RealmConfigurationBase.CreateRealm()
         at Realms.Realm.GetInstance(RealmConfigurationBase config)
         at Realms.Realm.GetInstance(String databasePath)
         at RealmTableInUse.Test.Tests.<Test_ParallelOpen>b__4_0() in /xxxx/Playground/RealmTableInUse/RealmTableInUse.Test/UnitTest1.cs:line 45
         at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
      --- End of stack trace from previous location ---
         at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
      --- End of stack trace from previous location ---
         at RealmTableInUse.Test.Tests.Test_ParallelOpen() in /xxxx/Playground/RealmTableInUse/RealmTableInUse.Test/UnitTest1.cs:line 53
         at RealmTableInUse.Test.Tests.Test_ParallelOpen() in /xxxx/Playground/RealmTableInUse/RealmTableInUse.Test/UnitTest1.cs:line 69
         at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted()
         at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter)
         at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke)
         at NUnit.Framework.Internal.Commands.TestMethodCommand.RunTestMethod(TestExecutionContext context)
         at NUnit.Framework.Internal.Commands.TestMethodCommand.Execute(TestExecutionContext context)
         at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.<Execute>b__0()
         at NUnit.Framework.Internal.Commands.DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)
      
      
      Failed!  - Failed:     1, Passed:     0, Skipped:     0, Total:     1, Duration: 440 ms - RealmTableInUse.Test.dll (net7.0)
      

      Relevant log output

      No response

            Assignee:
            Nikola Irinchev
            Reporter:
            Unito Sync Bot
            Archiver:
            Marc Greenfield

              Created:
              Updated:
              Resolved:
              Archived: