Uploaded image for project: 'Realm .NET SDK'
  1. Realm .NET SDK
  2. RNET-604

[Bug]: UI becomes unresponsive when GetInstance is used offline

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

      What happened?

      It's not as straightforward as the title suggests, but basically, the app runs at 1 frame every 5 seconds if I restart it offline after waiting for about 10 minutes with the app minimized.

      If I remove the call to Realm.GetInstance the issue goes away, but it's not exactly this line that causes it, it actually returns the Realm as it should. So when the app was unresponsive I paused it to see what it was doing on the main thread, and every single time the app was stuck at this line (see attached stacktrace):

      https://github.com/realm/realm-dotnet/blob/405e0bcf789dfdef629952c177f3a1693499d534/Realm/Realm/Native/HttpClientTransport.cs#L185

      The URL of the HTTP call was a Realm Auth endpoint.

      I don't know if this problem could have been originated server-side because I only noticed this issue recently even though I installed an older version of the app (from 3 months ago) and still could reproduce it. If this problem is really a bug present locally in realm-dotnet, I think we would have noticed it sooner given that it is so easily reproduced.

      I tested both on our main MongoDB Realm synced with an Atlas M10 cluster and on a MongoDB Realm for testing purposes on an M0, it's unlikely that it's being caused by something particular to a single MongoDB Realm even if the issue is really originated server-side.

      Repro steps

      1. Start the app while online
      2. Minimize the app and lock phone (I'm fairly sure the issue will happen even if the app is not minimized or the phone is not locked, but this is the most consistent way of reproducing)
      3. Wait for about 10 minutes on Android or 15 minutes on iOS (sometimes it takes less time, but again, this is the most consistent way to reproduce)
      4. Turn on airplane mode, maximize the app and then force close it
      5. Open it again while airplane mode is still on

      This may look like too much work to reproduce, but in a real-world scenario, it's actually very common:

      1. User starts an app online
      2. The app gets terminated by the OS to free RAM
      3. The connection fails
      4. User re-opens the app

      testapp.zip

      Version

      10.7.0

      What SDK flavour are you using?

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

      What type of application is this?

      Xamarin

      Client OS and version

      Android (tested on 12, 11, 10, 9 and 8), iOS (tested on 15)

      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
      This is the stack trace of the main thread when I pause the app.
      
      Realms.Native.HttpClientTransport.ExecuteRequest() in /Users/luccasclezar/Library/Caches/VisualStudio/8.0/Symbols/realm/realm-dotnet/ead7c424c900108b1f47b5bbe33f6972d0461966/Realm/Realm/Native/HttpClientTransport.cs:125
      System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start<Realms.Native.HttpClientTransport.<ExecuteRequest>d__9>(Realms.Native.HttpClientTransport stateMachine) in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:84
      Realms.Native.HttpClientTransport.ExecuteRequest(Realms.Native.HttpClientTransport.HttpClientRequest request, System.IntPtr callback) in 
      Realms.Native.HttpClientTransport.respond() in 
      Realms.Native.HttpClientTransport.ExecuteRequest() in D:/a/realm-dotnet/realm-dotnet/Realm/Realm/Native/HttpClientTransport.cs:185
      System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext(object stateMachine) in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1092
      System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:968
      System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:910
      System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run() in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1073
      System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.<>c.<.cctor>b__7_0(object state) in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs:379
      Foundation.NSAsyncSynchronizationContextDispatcher.Apply() in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:178
      UIKit.UIApplication.UIApplicationMain() in 
      UIKit.UIApplication.Main(string[] args, string principalClassName, string delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:69
      testapp.iOS.Application.Main(string[] args) in /Users/luccasclezar/Projects/testapp/testapp.iOS/Main.cs:17
      

      Relevant log output

      No response

            Assignee:
            nikola.irinchev@mongodb.com Nikola Irinchev
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: