Realm is closed but deleteRealm() errors out

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

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Won't Fix
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      What happened?

      When calling deleteRealm() after ensuring that the realm is closed (by realm.isClosed), I still get a RealmException:

      {{ RealmException: Cannot delete files of an open Realm: '.../6634c5a3b297ab517bc46ad0/default.realm' is still in use.. Error code: 2012.}}

      I just found this tangentially related issue which mentioned waiting or pausing the syncsession - I just wonder why the isClosed property is true then.

      I am closing the realm the following way:

        @override
        Future<void> closeRealm() async {
          final config = realm?.config;
          realm?.syncSession.pause();
          realm?.close();
          await atlasApp.currentUser?.logOut();
      
          await waitUntil(() => (realm?.isClosed ?? true) == true);
      
          Realm.deleteRealm(config!.path);
        }
      

      Repro steps

      1. Close the realm and get the exception

      Version

      3.22.3

      What Atlas Services are you using?

      Atlas Device Sync

      What type of application is this?

      Flutter Application

      Client OS and version

      Android 14

      Code snippets

      No response

      Stacktrace of the exception/crash you're getting

      No response

      Relevant log output

      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
      I/flutter (30426): │ RealmException: Cannot delete files of an open Realm: '.../6634c5a3b297ab517bc46ad0/default.realm' is still in use.. Error code: 2012.
      I/flutter (30426): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
      I/flutter (30426): │ #0   _raiseLastError.<anonymous closure> (package:realm_dart/src/handles/native/error_handling.dart:59:9)
      I/flutter (30426): │ #1   using (package:ffi/src/arena.dart:124:31)
      I/flutter (30426): │ #2   _raiseLastError (package:realm_dart/src/handles/native/error_handling.dart:48:3)
      

            Assignee:
            Unassigned
            Reporter:
            Unito Sync Bot
            Archiver:
            Marc Greenfield

              Created:
              Updated:
              Resolved:
              Archived: