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

Crash in dart due to debug output when app is being torn down

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

      There is a crash that is occurring in `DB::close_internal()` when a Dart app is being torn down because the Logger instance has already been destroyed when the `PersistedSyncMetadataManager` is destroyed. It only happens if the debug level is set to something higher than `info`.

      The issue is here: https://github.com/realm/realm-core/blob/master/src/realm/db.cpp#L2045-L2046


      From slack conversation: https://mongodb.slack.com/archives/C010R3CMP3N/p1723112587976859

      Does this ring a bell? Happens consistently on process exit when setting trace level to something finer than INFO in a test using realm-core 14.11.0.

      /Users/runner/work/realm-dart/realm-dart/packages/realm_dart/src/realm-core/src/realm/util/thread.cpp:177: [realm-core-14.11.0] pthread_mutex_lock() failed: Invalid mutex object provided
      0   librealm_dart.dylib                 0x000000011497ae8c _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 32
      1   librealm_dart.dylib                 0x000000011497ae04 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 396
      2   librealm_dart.dylib                 0x000000011497ac78 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 0
      3   librealm_dart.dylib                 0x000000011497b484 _ZN5realm4util5Mutex11lock_failedEi + 132
      4   librealm_dart.dylib                 0x0000000114976870 _ZN5realm4util12StderrLogger6do_logERKNS0_11LogCategoryENS2_5LevelERKNSt3__112basic_stringIcNS6_11char_traitsIcEENS6_9allocatorIcEEEE + 276
      5   librealm_dart.dylib                 0x0000000114803870 _ZN5realm8DBLogger6do_logERKNS_4util11LogCategoryENS2_5LevelERKNSt3__112basic_stringIcNS6_11char_traitsIcEENS6_9allocatorIcEEEE + 480
      6   librealm_dart.dylib                 0x000000011453dfb0 _ZN5realm4util6Logger6do_logIJEEEvRKNS0_11LogCategoryENS3_5LevelEPKcDpOT_ + 80
      7   librealm_dart.dylib                 0x00000001147fd930 _ZN5realm2DB14close_internalENSt3__111unique_lockINS_4util17InterprocessMutexEEEb + 564
      8   librealm_dart.dylib                 0x00000001147fb9c8 _ZN5realm2DB5closeEb + 168
      9   librealm_dart.dylib                 0x00000001147fd52c _ZN5realm2DBD2Ev + 24
      10  librealm_dart.dylib                 0x0000000114590fa4 _ZN5realm5_impl16RealmCoordinatorD2Ev + 920
      11  librealm_dart.dylib                 0x0000000114634b34 _ZN12_GLOBAL__N_128PersistedSyncMetadataManagerD0Ev + 84
      12  librealm_dart.dylib                 0x0000000114601838 _ZN5realm3app3AppD2Ev + 244
      13  librealm_dart.dylib                 0x000000011460e370 _ZNSt3__16vectorINS_4pairINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEN5realm4util7FlatMapIS7_NS_10shared_ptrINS8_3app3AppEEENS_4lessIvEENS0_INS1_IS7_SE_EENS5_ISH_EEEEEEEENS5_ISL_EEE22__base_destruct_at_endB8ue170006EPSL_ + 156
      14  librealm_dart.dylib                 0x0000000114600238 _ZN5realm4util7FlatMapINSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEENS1_IS8_NS2_10shared_ptrINS_3app3AppEEENS2_4lessIvEENS2_6vectorINS2_4pairIS8_SC_EENS6_ISH_EEEEEESE_NSF_INSG_IS8_SK_EENS6_ISL_EEEEED1Ev + 32
      15  libsystem_c.dylib                   0x0000000185a872e8 __cxa_finalize_ranges + 476
      16  libsystem_c.dylib                   0x0000000185a87070 exit + 44
      17  dart                                0x0000000104764fd4 dart + 233428
      18  dart                                0x000000010475bf50 dart + 196432
      19  dart                                0x000000010475af84 dart + 192388
      20  dyld                                0x000000018583f154 start + 2476
      !!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose
      

      This is a minimal reproduction:

      import 'package:realm_dart/realm.dart';
      
      void main(List<String> arguments) async {
        Realm.logger.setLogLevel(LogLevel.trace);
        final app = App(AppConfiguration('dummy'));
        // following throws since app doesn't exist,
        // but notice the crash on exit
        final user = await app.logIn(Credentials.anonymous());
      }
      

            Assignee:
            michael.wilkersonbarker@mongodb.com Michael Wilkerson-Barker (Inactive)
            Reporter:
            michael.wilkersonbarker@mongodb.com Michael Wilkerson-Barker (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: