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

Crash on write within Realm extension

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

      SDK and version

      SDK : Realm-cocoa, RealmSwift
      Version: 10.7.0

      Observations

      • How frequent do the crash occur?
        Each time
      • Does it happen in production or during dev/test?
        No production yet
      • Can the crash be reproduced by you?
        Yes
      • Can you provide instructions for how we can reproduce it?
        Execute included code below

      Crash log / stacktrace

      [realm-core-10.5.3] Assertion failed: m_notifier_sg->get_version() + 1 == new_version.version [22, 23]
      0   <app_name>                          0x000000010bfc7daf _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 31
      1   <app_name>                          0x000000010bfc8043 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 243
      2   <app_name>                          0x000000010b8629f1 _ZN5realm4util9terminateIJyyEEEvPKcS3_lDpT_ + 145
      3   <app_name>                          0x000000010b862630 _ZN5realm5_impl16RealmCoordinator12commit_writeERNS_5RealmE + 896
      4   <app_name>                          0x000000010b9af524 _ZN5realm5Realm18commit_transactionEv + 420
      5   <app_name>                          0x000000010b6b8ed7 -[RLMRealm commitWriteTransactionWithoutNotifying:error:] + 823
      6   <app_name>                          0x000000010b7a562c $s10RealmSwift0A0V11commitWrite16withoutNotifyingySaySo20RLMNotificationTokenCG_tKF + 204
      7   <app_name>                          0x000000010b7a4fa9 $s10RealmSwift0A0V5write16withoutNotifying_xSaySo20RLMNotificationTokenCG_xyKXEtKlF + 425
      8   <app_name>                          0x000000010b32a8e6 $s10RealmSwift0A0V10FlightWaveE11replaceList6values7keyPath_ySayxG_s03KeyI0Cyq_AA0F0CyxGGq_tAA0A15CollectionValueRzSo0aB6ObjectCRb_r0_lF + 854
      9   <app_name>                          0x000000010b35899d $s10FlightWave14UserControllerC6update33_11DC5E2027EAD4317D3E31DCF47BED0BLL23actionDefinitionForRoleyAA0P0C_tF + 333
      10  <app_name>                          0x000000010b358674 $s10FlightWave14UserControllerC3run011withEnsuredC0ySo7RLMUserC_tFyAA0C0CcfU2_ + 340
      11  <app_name>                          0x000000010b30f71f $s10FlightWave4UserCIegg_ACIegn_TR + 15
      12  Combine                             0x00007fff4b5a5dd6 $s7Combine11SubscribersO4SinkC7receiveyAC6DemandVxF + 54
      13  Combine                             0x00007fff4b5a64d0 $s7Combine11SubscribersO4SinkCy_xq_GAA10SubscriberA2aGP7receiveyAC6DemandV5InputQzFTW + 16
      14  Combine                             0x00007fff4b634690 $s7Combine10PublishersO3MapV5Inner33_5A6CD15A64659A6248DAF677D4BB6188LLV7receiveyAA11SubscribersO6DemandV6OutputQzF + 144
      15  <app_name>                          0x000000010b73e80f $s10RealmSwift0A10CollectionPAAE8_observe2on_So20RLMNotificationTokenCSo17OS_dispatch_queueCSg_qd__t5InputQyd__Rsz7Combine10SubscriberRd__s5Error_p7FailureRtd__lFyAA0aC6ChangeOyxGcfU_ + 463
      16  <app_name>                          0x000000010b7c57e5 $s10RealmSwift0A16CollectionChangeOyAA7ResultsVyxGGIegn_AGIegg_AA0aC5ValueRzlTR + 69
      17  <app_name>                          0x000000010b7c4c74 $s10RealmSwift0A16CollectionChangeOyAA7ResultsVyxGGIegg_AGIegn_AA0aC5ValueRzlTR + 52
      18  <app_name>                          0x000000010b7b3bc9 $s10RealmSwift20ObservableCollectionPAAE16wrapObserveBlockyy011BackingObjcD0QzSg_So19RLMCollectionChangeCSgs5Error_pSgtcyAA0adK0OyxGcFyAG_AjLtcfU_ + 1625
      19  <app_name>                          0x000000010b7b429a $s10RealmSwift20ObservableCollectionPAAE16wrapObserveBlockyy011BackingObjcD0QzSg_So19RLMCollectionChangeCSgs5Error_pSgtcyAA0adK0OyxGcFyAG_AjLtcfU_TA + 106
      20  <app_name>                          0x000000010b767d04 $sSo10RLMResultsCyyXlGSgSo19RLMCollectionChangeCSgs5Error_pSgIegngg_AdgIIegggg_TR + 84
      21  <app_name>                          0x000000010b767e11 $sSo10RLMResultsCyyXlGSgSo19RLMCollectionChangeCSgs5Error_pSgIegggg_AdGSo7NSErrorCSgIeyByyy_TR + 161
      22  <app_name>                          0x000000010b533654 _ZN12_GLOBAL__N_125CollectionCallbackWrapperclERKN5realm19CollectionChangeSetESt13exception_ptr + 388
      23  <app_name>                          0x000000010b5332b5 _ZN5realm24CollectionChangeCallback4ImplIN12_GLOBAL__N_125CollectionCallbackWrapperEE5afterERKNS_19CollectionChangeSetE + 69
      24  <app_name>                          0x000000010b852816 _ZN5realm24CollectionChangeCallback5afterERKNS_19CollectionChangeSetE + 38
      25  <app_name>                          0x000000010b852779 _ZZN5realm5_impl18CollectionNotifier13after_advanceEvENK4$_10clINS_4util17CheckedUniqueLockENS1_8CallbackEEEDaRT_RT0_ + 169
      26  <app_name>                          0x000000010b838490 _ZN5realm5_impl18CollectionNotifier17for_each_callbackIZNS1_13after_advanceEvE4$_10EEvOT_ + 256
      27  <app_name>                          0x000000010b838389 _ZN5realm5_impl18CollectionNotifier13after_advanceEv + 25
      28  <app_name>                          0x000000010b866382 _ZN5realm5_impl16RealmCoordinator23process_available_asyncERNS_5RealmE + 1426
      29  <app_name>                          0x000000010b9afcaa _ZN5realm5Realm6notifyEv + 378
      30  <app_name>                          0x000000010b8bfe20 _ZZN5realm5_impl17WeakRealmNotifier17bind_to_schedulerEvENK3$_0clEv + 64
      31  <app_name>                          0x000000010b8bfdbd _ZNSt3__1L8__invokeIRZN5realm5_impl17WeakRealmNotifier17bind_to_schedulerEvE3$_0JEEEDTclclsr3std3__1E7forwardIT_Efp_Espclsr3std3__1E7forwardIT0_Efp0_EEEOS6_DpOS7_ + 29
      32  <app_name>                          0x000000010b8bfd6d _ZNSt3__128__invoke_void_return_wrapperIvE6__callIJRZN5realm5_impl17WeakRealmNotifier17bind_to_schedulerEvE3$_0EEEvDpOT_ + 29
      33  <app_name>                          0x000000010b8bfd3d _ZNSt3__110__function12__alloc_funcIZN5realm5_impl17WeakRealmNotifier17bind_to_schedulerEvE3$_0NS_9allocatorIS5_EEFvvEEclEv + 29
      34  <app_name>                          0x000000010b8be63e _ZNSt3__110__function6__funcIZN5realm5_impl17WeakRealmNotifier17bind_to_schedulerEvE3$_0NS_9allocatorIS5_EEFvvEEclEv + 30
      35  <app_name>                          0x000000010b901765 _ZNKSt3__110__function12__value_funcIFvvEEclEv + 53
      36  <app_name>                          0x000000010b8f6345 _ZNKSt3__18functionIFvvEEclEv + 21
      37  <app_name>                          0x000000010bb7575c _ZZN12_GLOBAL__N_116RunLoopScheduler19set_notify_callbackENSt3__18functionIFvvEEEENK3$_0clEPv + 28
      38  <app_name>                          0x000000010bb75735 _ZZN12_GLOBAL__N_116RunLoopScheduler19set_notify_callbackENSt3__18functionIFvvEEEEN3$_08__invokeEPv + 21
      39  CoreFoundation                      0x00007fff2038f38a __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
      40  CoreFoundation                      0x00007fff2038f282 __CFRunLoopDoSource0 + 180
      41  CoreFoundation                      0x00007fff2038e7c6 __CFRunLoopDoSources0 + 346
      42  CoreFoundation                      0x00007fff20388f2f __CFRunLoopRun + 878
      43  CoreFoundation                      0x00007fff203886d6 CFRunLoopRunSpecific + 567
      44  GraphicsServices                    0x00007fff2bededb3 GSEventRunModal + 139
      45  UIKitCore                           0x00007fff24690e0b -[UIApplication _run] + 912
      46  UIKitCore                           0x00007fff24695cbc UIApplicationMain + 101
      47  SwiftUI                             0x00007fff574afbc7 $s7SwiftUI17KitRendererCommon33_ACC2C5639A7D76F611E170E831FCA491LLys5NeverOyXlXpFAESpySpys4Int8VGSgGXEfU_ + 119
      48  SwiftUI                             0x00007fff574afb3f $s7SwiftUI6runAppys5NeverOxAA0D0RzlF + 143
      49  SwiftUI                             0x00007fff56fe712d $s7SwiftUI3AppPAAE4mainyyFZ + 61
      50  <app_name>                          0x000000010b327300 $s10FlightWave0aB3AppV5$mainyyFZ + 48
      51  <app_name>                          0x000000010b327394 main + 20
      52  libdyld.dylib                       0x00007fff202593e9 start + 1!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose2021-03-10 12:09:50.741961-0800 <app_name>[93699:6830215] /Users/elight/Library/Caches/JetBrains/AppCode2020.3/DerivedData/<app_name>-gpxptcldtfahlmfjlrmupnkbvmgn/SourcePackages/checkouts/realm-core/src/realm/object-store/impl/realm_coordinator.cpp:744: [realm-core-10.5.3] Assertion failed: m_notifier_sg->get_version() + 1 == new_version.version [22, 23]
      0   <app_name>                          0x000000010bfc7daf _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 31
      1   <app_name>                          0x000000010bfc8043 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 243
      2   <app_name>                          0x000000010b8629f1 _ZN5realm4util9terminateIJyyEEEvPKcS3_lDpT_ + 145
      3   <app_name>                          0x000000010b862630 _ZN5realm5_impl16RealmCoordinator12commit_writeERNS_5RealmE + 896
      4   <app_name>                          0x000000010b9af524 _ZN5realm5Realm18commit_transactionEv + 420
      5   <app_name>                          0x000000010b6b8ed7 -[RLMRealm commitWriteTransactionWithoutNotifying:error:] + 823
      6   <app_name>                          0x000000010b7a562c $s10RealmSwift0A0V11commitWrite16withoutNotifyingySaySo20RLMNotificationTokenCG_tKF + 204
      7   <app_name>                          0x000000010b7a4fa9 $s10RealmSwift0A0V5write16withoutNotifying_xSaySo20RLMNotificationTokenCG_xyKXEtKlF + 425
      8   <app_name>                          0x000000010b32a8e6 $s10RealmSwift0A0V10FlightWaveE11replaceList6values7keyPath_ySayxG_s03KeyI0Cyq_AA0F0CyxGGq_tAA0A15CollectionValueRzSo0aB6ObjectCRb_r0_lF + 854
      9   <app_name>                          0x000000010b35899d $s10FlightWave14UserControllerC6update33_11DC5E2027EAD4317D3E31DCF47BED0BLL23actionDefinitionForRoleyAA0P0C_tF + 333
      10  <app_name>                          0x000000010b358674 $s10FlightWave14UserControllerC3run011withEnsuredC0ySo7RLMUserC_tFyAA0C0CcfU2_ + 340
      11  <app_name>                          0x000000010b30f71f $s10FlightWave4UserCIegg_ACIegn_TR + 15
      12  Combine                             0x00007fff4b5a5dd6 $s7Combine11SubscribersO4SinkC7receiveyAC6DemandVxF + 54
      13  Combine                             0x00007fff4b5a64d0 $s7Combine11SubscribersO4SinkCy_xq_GAA10SubscriberA2aGP7receiveyAC6DemandV5InputQzFTW + 16
      14  Combine                             0x00007fff4b634690 $s7Combine10PublishersO3MapV5Inner33_5A6CD15A64659A6248DAF677D4BB6188LLV7receiveyAA11SubscribersO6DemandV6OutputQzF + 144
      15  <app_name>                          0x000000010b73e80f $s10RealmSwift0A10CollectionPAAE8_observe2on_So20RLMNotificationTokenCSo17OS_dispatch_queueCSg_qd__t5InputQyd__Rsz7Combine10SubscriberRd__s5Error_p7FailureRtd__lFyAA0aC6ChangeOyxGcfU_ + 463
      16  <app_name>                          0x000000010b7c57e5 $s10RealmSwift0A16CollectionChangeOyAA7ResultsVyxGGIegn_AGIegg_AA0aC5ValueRzlTR + 69
      17  <app_name>                          0x000000010b7c4c74 $s10RealmSwift0A16CollectionChangeOyAA7ResultsVyxGGIegg_AGIegn_AA0aC5ValueRzlTR + 52
      18  <app_name>                          0x000000010b7b3bc9 $s10RealmSwift20ObservableCollectionPAAE16wrapObserveBlockyy011BackingObjcD0QzSg_So19RLMCollectionChangeCSgs5Error_pSgtcyAA0adK0OyxGcFyAG_AjLtcfU_ + 1625
      19  <app_name>                          0x000000010b7b429a $s10RealmSwift20ObservableCollectionPAAE16wrapObserveBlockyy011BackingObjcD0QzSg_So19RLMCollectionChangeCSgs5Error_pSgtcyAA0adK0OyxGcFyAG_AjLtcfU_TA + 106
      20  <app_name>                          0x000000010b767d04 $sSo10RLMResultsCyyXlGSgSo19RLMCollectionChangeCSgs5Error_pSgIegngg_AdgIIegggg_TR + 84
      21  <app_name>                          0x000000010b767e11 $sSo10RLMResultsCyyXlGSgSo19RLMCollectionChangeCSgs5Error_pSgIegggg_AdGSo7NSErrorCSgIeyByyy_TR + 161
      22  <app_name>                          0x000000010b533654 _ZN12_GLOBAL__N_125CollectionCallbackWrapperclERKN5realm19CollectionChangeSetESt13exception_ptr + 388
      23  <app_name>                          0x000000010b5332b5 _ZN5realm24CollectionChangeCallback4ImplIN12_GLOBAL__N_125CollectionCallbackWrapperEE5afterERKNS_19CollectionChangeSetE + 69
      24  <app_name>                          0x000000010b852816 _ZN5realm24CollectionChangeCallback5afterERKNS_19CollectionChangeSetE + 38
      25  <app_name>                          0x000000010b852779 _ZZN5realm5_impl18CollectionNotifier13after_advanceEvENK4$_10clINS_4util17CheckedUniqueLockENS1_8CallbackEEEDaRT_RT0_ + 169
      26  <app_name>                          0x000000010b838490 _ZN5realm5_impl18CollectionNotifier17for_each_callbackIZNS1_13after_advanceEvE4$_10EEvOT_ + 256
      27  <app_name>                          0x000000010b838389 _ZN5realm5_impl18CollectionNotifier13after_advanceEv + 25
      28  <app_name>                          0x000000010b866382 _ZN5realm5_impl16RealmCoordinator23process_available_asyncERNS_5RealmE + 1426
      29  <app_name>                          0x000000010b9afcaa _ZN5realm5Realm6notifyEv + 378
      30  <app_name>                          0x000000010b8bfe20 _ZZN5realm5_impl17WeakRealmNotifier17bind_to_schedulerEvENK3$_0clEv + 64
      31  <app_name>                          0x000000010b8bfdbd _ZNSt3__1L8__invokeIRZN5realm5_impl17WeakRealmNotifier17bind_to_schedulerEvE3$_0JEEEDTclclsr3std3__1E7forwardIT_Efp_Espclsr3std3__1E7forwardIT0_Efp0_EEEOS6_DpOS7_ + 29
      32  <app_name>                          0x000000010b8bfd6d _ZNSt3__128__invoke_void_return_wrapperIvE6__callIJRZN5realm5_impl17WeakRealmNotifier17bind_to_schedulerEvE3$_0EEEvDpOT_ + 29
      33  <app_name>                          0x000000010b8bfd3d _ZNSt3__110__function12__alloc_funcIZN5realm5_impl17WeakRealmNotifier17bind_to_schedulerEvE3$_0NS_9allocatorIS5_EEFvvEEclEv + 29
      34  <app_name>                          0x000000010b8be63e _ZNSt3__110__function6__funcIZN5realm5_impl17WeakRealmNotifier17bind_to_schedulerEvE3$_0NS_9allocatorIS5_EEFvvEEclEv + 30
      35  <app_name>                          0x000000010b901765 _ZNKSt3__110__function12__value_funcIFvvEEclEv + 53
      36  <app_name>                          0x000000010b8f6345 _ZNKSt3__18functionIFvvEEclEv + 21
      37  <app_name>                          0x000000010bb7575c _ZZN12_GLOBAL__N_116RunLoopScheduler19set_notify_callbackENSt3__18functionIFvvEEEENK3$_0clEPv + 28
      38  <app_name>                          0x000000010bb75735 _ZZN12_GLOBAL__N_116RunLoopScheduler19set_notify_callbackENSt3__18functionIFvvEEEEN3$_08__invokeEPv + 21
      39  CoreFoundation                      0x00007fff2038f38a __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
      40  CoreFoundation                      0x00007fff2038f282 __CFRunLoopDoSource0 + 180
      41  CoreFoundation                      0x00007fff2038e7c6 __CFRunLoopDoSources0 + 346
      42  CoreFoundation                      0x00007fff20388f2f __CFRunLoopRun + 878
      43  CoreFoundation                      0x00007fff203886d6 CFRunLoopRunSpecific + 567
      44  GraphicsServices                    0x00007fff2bededb3 GSEventRunModal + 139
      45  UIKitCore                           0x00007fff24690e0b -[UIApplication _run] + 912
      46  UIKitCore                           0x00007fff24695cbc UIApplicationMain + 101
      47  SwiftUI                             0x00007fff574afbc7 $s7SwiftUI17KitRendererCommon33_ACC2C5639A7D76F611E170E831FCA491LLys5NeverOyXlXpFAESpySpys4Int8VGSgGXEfU_ + 119
      48  SwiftUI                             0x00007fff574afb3f $s7SwiftUI6runAppys5NeverOxAA0D0RzlF + 143
      49  SwiftUI                             0x00007fff56fe712d $s7SwiftUI3AppPAAE4mainyyFZ + 61
      50  <app_name>                          0x000000010b327300 $s10FlightWave0aB3AppV5$mainyyFZ + 48
      51  <app_name>                          0x000000010b327394 main + 20
      52  libdyld.dylib                       0x00007fff202593e9 start + 1!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose
      Signal: SIGABRT (signal SIGABRT)
      Terminated due to signal 6
      

      Steps & Code to Reproduce

      extension Realm {
          func replaceList<V, T> (values: [V], keyPath: KeyPath<T, List<V>>, _ object: T) where T : Object {
      
              let diff = values.difference(from: object[keyPath: keyPath])
      
              try! write {
                  for change in diff.insertions {
                      if case .insert(let index, let value, _) = change {
                          object[keyPath: keyPath].insert(
                                  value,
                                  at: index
                          )
                      }
                  }
      
                  for change in diff.removals {
                      if case .remove(let index, _, _) = change {
                          object[keyPath: keyPath].remove(at: index)
                      }
                  }
              }
          }
      }
      

      Role class (Realm Object)

      @objcMembers class Role: Object, ObjectKeyIdentifable {
          dynamic var _id = ObjectId.generate()
          override class func primaryKey () -> String? { "_id" }
          ///---------------------------------------------------
          dynamic var user_id: String?
          dynamic var name: String = ""
          let actions = List<String>()
          let policies = List<Policy>()
      }
      

      I call this code from:

      private func update (actionDefinitionForRole role: Role) {
              role.realm!.replaceList(values: role.type.actionDefinitions(), keyPath: \.actions, role) /// .actionDefinitions() returns an array of string enums
          }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: