Realm-cocoa: Realm Crash: Assertion failed: list.col < list.observer->changes.size()

Created on 24 Feb 2017  路  11Comments  路  Source: realm/realm-cocoa

Goals

I'm attempting to observe 3 objects through KVO in one of my ViewControllers. When I leave the view I remove the observers. Once I leave the view I re-sync my data causing some old objects to be deleted from the Realm.

Expected Results

The application should not crash

Actual Results

The application crashes due to an assertion error:
Assertion failed: list.col < list.observer->changes.size()

Here is the stack trace:

/Users/matthew/Projects/AppTree/ios/apptreerevolution/Pods/Realm/Realm/ObjectStore/src/impl/transact_log_handler.cpp:147: [realm-core-2.3.0] Assertion failed: list.col < list.observer->changes.size()
0   Realm                               0x000000010779b568 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 40
1   Realm                               0x000000010779b86a _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 506
2   Realm                               0x000000010772586d _ZN12_GLOBAL__N_110KVOAdapter6beforeERN5realm11SharedGroupE + 4253
3   Realm                               0x000000010770feca _ZN12_GLOBAL__N_122KVOTransactLogObserver14parse_completeEv + 58
4   Realm                               0x000000010770fc45 _ZN5realm11SharedGroup15do_advance_readIN12_GLOBAL__N_122KVOTransactLogObserverEEEbPT_NS_9VersionIDERNS_5_impl7HistoryE + 501
5   Realm                               0x000000010770fa3c _ZN5realm11SharedGroup12advance_readIN12_GLOBAL__N_122KVOTransactLogObserverEEEvPT_NS_9VersionIDE + 396
6   Realm                               0x000000010770f89b _ZN5realm5_impl17SharedGroupFriend12advance_readIN12_GLOBAL__N_122KVOTransactLogObserverEEEvRNS_11SharedGroupEPT_NS_9VersionIDE + 59
7   Realm                               0x000000010770f84b _ZN5realm14LangBindHelper12advance_readIN12_GLOBAL__N_122KVOTransactLogObserverEEEvRNS_11SharedGroupEOT_NS_9VersionIDE + 59
8   Realm                               0x000000010770f75c _ZZN5realm5_impl11transaction7advanceERNS_11SharedGroupEPNS_14BindingContextERNS0_15NotifierPackageEENK3$_0clIJN12_GLOBAL__N_122KVOTransactLogObserverEEEEDaDpOT_ + 108
9   Realm                               0x00000001076f3ba1 _ZN12_GLOBAL__N_126advance_with_notificationsIZN5realm5_impl11transaction7advanceERNS1_11SharedGroupEPNS1_14BindingContextERNS2_15NotifierPackageEE3$_0EEvS7_S5_OT_S9_ + 1441
10  Realm                               0x00000001076f35ec _ZN5realm5_impl11transaction7advanceERNS_11SharedGroupEPNS_14BindingContextERNS0_15NotifierPackageE + 60
11  Realm                               0x00000001074918c8 _ZN5realm5_impl16RealmCoordinator16advance_to_readyERNS_5RealmE + 696
12  Realm                               0x000000010768a99c _ZN5realm5Realm6notifyEv + 748
13  Realm                               0x000000010772b79b _ZNK5realm5_impl17WeakRealmNotifier8CallbackclEv + 75
14  Realm                               0x000000010772c61c _ZZN5realm4util15EventLoopSignalINS_5_impl17WeakRealmNotifier8CallbackEEC1EOS4_ENKUlPvE_clES7_ + 28
15  Realm                               0x000000010772c5f8 _ZZN5realm4util15EventLoopSignalINS_5_impl17WeakRealmNotifier8CallbackEEC1EOS4_ENUlPvE_8__invokeES7_ + 24
16  CoreFoundation                      0x000000010be74761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17  CoreFoundation                      0x000000010be5998c __CFRunLoopDoSources0 + 556
18  CoreFoundation                      0x000000010be58e76 __CFRunLoopRun + 918
19  CoreFoundation                      0x000000010be58884 CFRunLoopRunSpecific + 420
20  GraphicsServices                    0x0000000110f2ca6f GSEventRunModal + 161
21  UIKit                               0x0000000108904c68 UIApplicationMain + 159
22  AppTreeRevolution AppStore          0x0000000102aa0def main + 111
23  libdyld.dylib                       0x000000010d47a68d start + 1
IMPORTANT: if you see this error, please send this log to [email protected].

Steps to Reproduce

What are steps we can follow to reproduce this issue?

Using RxSwift, I start observing a realm object for the invalidated property.

_editingDataSetItemInvalidatedSubscription = newItem?
                .rx.observe(Bool.self, "invalidated")
                .subscribe(onNext:  { [weak self] invalidated in
                    if invalidated == true {
                        self?.resolver.dataSetItem = nil
                        self?.editingDataSetItem = nil
                    }
                })

In my viewWillDisappear I dispose the observer using _editingDataSetItemInvalidatedSubscription.dispose()`

When I return to the previous view I force a sync in our system which deletes old objects and builds new ones. I have confirmed that the invalidated observer is disposed prior to this sync happening, I have also confirmed the VC that started the observation has been dealloc'd.

Once the sync mechanism deletes the object I receive the realm crash. I have tested removing the rx.observe code and the issue does not occur.
I have also tried reverting to Realm 2.2.0 and the crash does not occur. My workaround is currently to revert to 2.2.0

#
Realm version:
2.3.0+ ( I tested on both 2.3.0 and 2.4.3 )

Xcode version: 8.2

iOS/OSX version: 10.1

Dependency manager + version: CocoaPods 1.2.0

T-Bug-Crash

All 11 comments

Hi @matthewtsmith. Thanks for reaching out about this! My apologies for the delay in getting back to you about this. We'll have one of the engineers review what you've shared and follow-up with a solution or additional questions. Thanks!

Thanks for getting in touch, and we're sorry about the crash. Would you be willing to provide a demonstration project we can run to reproduce the bug and examine what is going on?

Hi @matthewtsmith. Just echoing @austinzheng's request - would you be able to provide us with a sample project so we can reproduce the issue? If you'd like to share it privately, please email it to [email protected] and link to this issue. Thanks.

@austinzheng @istx25 We are not comfortable with giving you our primary code base but I will attempt to create a sample project that reproduces it.

That's fine. Please let us know/share it once you have. Thanks.

@matthewtsmith have you had any luck reproducing this in a shareable project? We'd love to resolve this with you. Thanks!

@jpsim No, unfortunately I have not had the time. I do think I will have some bandwidth today to attempt a sample project. I'm also going to update to Realm 2.4.4 to see if my main project still has the issue.

Hi @matthewtsmith! Did updating to the latest version of Realm solve this issue? If not, are you still able to provide us with a sample app so we can analyze the problem? Thanks a lot!

@TimOliver No, I still have the issue in the latest Realm version in our main application. I did create a simple sample project that I thought might reproduce this issue but the crash did not occur. I've attached the sample project I thought would reproduce it.

My assumption with this crash is that it happens when you remove a KVO observer from a RealmObject in the main thread and then delete that same realm object in another thread.

If you could provide some insight into what the Realm stack trace is trying to do I may be able to modify my example code to reproduce it. From what I can see it looks like its trying to go out and notify its observers of changes. As I mentioned in my first post, if I remove the "invalidated" observer on the RealmObject on the main thread the crash no longer occurs.

RealmCrashExample.zip

The zip archive you sent shows Realm 2.4.1 was last installed via CocoaPods, not Realm 2.4.4. And as you mentioned, it doesn't reproduce the assertion failure.

This should be fixed in 2.5.0.

Was this page helpful?
0 / 5 - 0 ratings