realm / realm-core

Core database component for the Realm Mobile Database SDKs
https://realm.io
Apache License 2.0
1.02k stars 165 forks source link

Crashes with [realm-core-2.8.1] Assertion failed: top_size == 3 || top_size == 5 || top_size == 7 with (top_size) #2819

Closed bdash closed 6 years ago

bdash commented 7 years ago

@Reggian commented on Wed Aug 23 2017

Hi,

I am experiencing consistent crashes for some users. Can anyone please help me solve this?

Goals

I am trying to initialise the realm with a custom configuration (migration purposes).

Expected Results

I have provided the error object. The realm initialisation should return nil with the filled error and not crash the app.

Actual Results

For a small number of users the app constantly crashes upon launch. Here is the stack trace obtained via Crashlytics:

CRASH_INFO_ENTRY_0
abort() called
Crashed: com.apple.main-thread
0  libsystem_kernel.dylib         0x185701014 __pthread_kill + 8
1  libsystem_pthread.dylib        0x1857cb264 pthread_kill + 112
2  libsystem_c.dylib              0x1856759c4 abort + 140
3  Realm                          0x1009710b0 realm::util::terminate(char const*, char const*, long) + 10
4  Realm                          0x100971594 realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 776
5  libsystem_pthread.dylib        0x1857cb264 pthread_kill + 112
6  Realm                          0x100971944 realm::util::terminate_with_info(char const*, char const*, long, char const*, std::initializer_list<realm::util::Printable>&&) + 452
7  Realm                          0x100904134 void realm::util::terminate_with_info<unsigned long&, unsigned long&>(char const*, int, char const*, char const*, unsigned long&&&, unsigned long&&&) + 62
8  Realm                          0x100a1caa4 realm::Group::attach(unsigned long, bool) + 172
9  Realm                          0x100a27a84 realm::SharedGroup::do_begin_read(realm::VersionID, bool) + 76
10 Realm                          0x100a26e50 realm::SharedGroup::begin_read(realm::VersionID) + 36
11 Realm                          0x1008d6524 realm::Realm::begin_read(realm::VersionID) (shared_realm.cpp:213)
12 Realm                          0x1008d5874 realm::Realm::read_group() (shared_realm.cpp:202)
13 Realm                          0x1008d4ef0 realm::Realm::Realm(realm::Realm::Config, std::__1::shared_ptr<realm::_impl::RealmCoordinator>) (memory:4045)
14 Realm                          0x100821e5c realm::Realm::make_shared_realm(realm::Realm::Config, std::__1::shared_ptr<realm::_impl::RealmCoordinator>)::make_shared_enabler::make_shared_enabler(realm::Realm::Config, std::__1::shared_ptr<realm::_impl::RealmCoordinator>) (memory:4604)
15 Realm                          0x100821ce4 std::__1::shared_ptr<realm::Realm::make_shared_realm(realm::Realm::Config, std::__1::shared_ptr<realm::_impl::RealmCoordinator>)::make_shared_enabler> std::__1::shared_ptr<realm::Realm::make_shared_realm(realm::Realm::Config, std::__1::shared_ptr<realm::_impl::RealmCoordinator>)::make_shared_enabler>::make_shared<realm::Realm::Config, std::__1::shared_ptr<realm::_impl::RealmCoordinator> >(realm::Realm::Config&&, std::__1::shared_ptr<realm::_impl::RealmCoordinator>&&) (memory:4604)
16 Realm                          0x10081ded0 realm::_impl::RealmCoordinator::get_realm(realm::Realm::Config) (memory:4326)
17 Realm                          0x1008d6824 realm::Realm::get_shared_realm(realm::Realm::Config) (shared_realm.hpp:148)
18 Realm                          0x1008b3480 +[RLMRealm realmWithConfiguration:error:] (RLMRealm.mm:365)
19 MyApp                          0x100120978 +[RLMRealm(MYDefaultRealm) my_defaultRealm] (RLMRealm+MYDefaultRealm.m:21)
20 MyApp                          0x1001f2cbc +[MYDataStore setupStore] (MYDataStore.m:548)
21 MyApp                          0x10019b6d8 -[MYDirector init] (MYDirector.m:66)
22 MyApp                          0x10019b664 __28+[MYDirector sharedDirector]_block_invoke (MYDirector.m:56)
23 libdispatch.dylib              0x1855be9a0 _dispatch_client_callout + 16
24 libdispatch.dylib              0x1855bf6cc dispatch_once_f + 56
25 MyApp                          0x10019b63c +[MYDirector sharedDirector] (once.h:75)
26 MyApp                          0x100110818 -[AppDelegate application:didFinishLaunchingWithOptions:] (AppDelegate.m:87)
27 UIKit                          0x18c8a9204 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 380
28 UIKit                          0x18cab5738 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3452
29 UIKit                          0x18cabb1e0 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1684
30 UIKit                          0x18cacfd18 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke.3151 + 48
31 UIKit                          0x18cab8474 -[UIApplication workspaceDidEndTransaction:] + 168
32 FrontBoardServices             0x1882af884 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36
33 FrontBoardServices             0x1882af6f0 -[FBSSerialQueue _performNext] + 176
34 FrontBoardServices             0x1882afaa0 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
35 CoreFoundation                 0x1866b542c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
36 CoreFoundation                 0x1866b4d9c __CFRunLoopDoSources0 + 540
37 CoreFoundation                 0x1866b29a8 __CFRunLoopRun + 744
38 CoreFoundation                 0x1865e2da4 CFRunLoopRunSpecific + 424
39 UIKit                          0x18c8a2384 -[UIApplication _run] + 652
40 UIKit                          0x18c89d058 UIApplicationMain + 208
41 MyApp                          0x1001098bc main (main.m:16)
42 libdyld.dylib                  0x1855f159c start + 4

Steps to Reproduce

I can not find the steps to reproduce. I have managed to obtain the realm db file from one of the crashing apps but when swapping the container with the obtained db the app on my phone launches without crashing.

Code Sample

MYDataStore.m

//// Configure Realm
RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
config.schemaVersion = 11;
config.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) {
    // Migrate
    // ...
};

[RLMRealmConfiguration setDefaultConfiguration:config];
RLMRealm *realm = [RLMRealm my_defaultRealm]; // (MYDataStore.m:548)

RLMRealm+MYDefaultRealm.m

+ (instancetype)my_defaultRealm
{
    NSError *error = nil;
    RLMRealm *realm = [RLMRealm realmWithConfiguration:[RLMRealmConfiguration defaultConfiguration] error:&error]; // (RLMRealm+MYDefaultRealm.m:21)
    if (realm == nil) {
        // Handle error.
    }
    return realm;
}

Version of Realm and Tooling

ProductName:    Mac OS X
ProductVersion: 10.12.6
BuildVersion:   16G29

/Applications/Xcode.app/Contents/Developer
Xcode 8.3.3
Build version 8E3004b

/Users/reggian/.gem/ruby/2.0.0/bin/pod
1.3.1
Realm (2.9.1)
Realm (= 2.9.1)

/bin/bash
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)

/usr/local/bin/carthage
0.24.0
(not in use here)

/usr/bin/git
git version 2.11.0 (Apple Git-81)

@Reggian commented on Thu Aug 24 2017

I have managed to obtain another problematic realm file. This is what I have stumbled upon when launched from the app.

group.cpp:308: [realm-core-2.8.1] Assertion failed: top_size == 3 || top_size == 5 || top_size == 7 with (top_size) =  [0]
0   Realm                               0x000000010113ed70 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 44
1   Realm                               0x000000010113f258 _ZN5realm4util19terminate_with_infoEPKcS2_lS2_OSt16initializer_listINS0_9PrintableEE + 452
2   Realm                               0x00000001012aee7c _ZN5realm14SortDescriptor6SorterC1ERKNSt3__16vectorINS3_IPKNS_10ColumnBaseENS2_9allocatorIS6_EEEENS7_IS9_EEEERKNS3_IbNS7_IbEEEERKNS_6ColumnIxEE + 0
3   Realm                               0x00000001011ec7f4 _ZN5realm5Group6attachEmb + 180
4   Realm                               0x00000001011f81b8 _ZN5realm11SharedGroup13do_begin_readENS_9VersionIDEb + 76
5   Realm                               0x00000001011f757c _ZN5realm11SharedGroup10begin_readENS_9VersionIDE + 36
6   Realm                               0x00000001010208c8 _ZN5realm5Realm10begin_readENS_9VersionIDE + 180
7   Realm                               0x000000010101eaf0 _ZN5realm5Realm10read_groupEv + 80
8   Realm                               0x000000010101cf84 _ZN5realm5RealmC2ENS0_6ConfigENSt3__110shared_ptrINS_5_impl16RealmCoordinatorEEE + 1240
9   Realm                               0x0000000100e4d208 _ZZN5realm5Realm17make_shared_realmENS0_6ConfigENSt3__110shared_ptrINS_5_impl16RealmCoordinatorEEEEN19make_shared_enablerC2ES1_S6_ + 172
10  Realm                               0x0000000100e4d144 _ZZN5realm5Realm17make_shared_realmENS0_6ConfigENSt3__110shared_ptrINS_5_impl16RealmCoordinatorEEEEN19make_shared_enablerC1ES1_S6_ + 28
11  Realm                               0x0000000100e4caa8 _ZNSt3__110shared_ptrIZN5realm5Realm17make_shared_realmENS2_6ConfigENS0_INS1_5_impl16RealmCoordinatorEEEE19make_shared_enablerE11make_sharedIJS3_S6_EEES8_DpOT_ + 1196
12  Realm                               0x0000000100e3fb5c _ZN5realm5Realm17make_shared_realmENS0_6ConfigENSt3__110shared_ptrINS_5_impl16RealmCoordinatorEEE + 76
13  Realm                               0x0000000100e3edc8 _ZN5realm5_impl16RealmCoordinator9get_realmENS_5Realm6ConfigE + 1564
14  Realm                               0x0000000101020ce4 _ZN5realm5Realm16get_shared_realmENS0_6ConfigE + 140
15  Realm                               0x0000000100fbca98 +[RLMRealm realmWithConfiguration:error:] + 2552
16  MyApp                               0x0000000100109754 +[RLMRealm(MYDefaultRealm) my_defaultRealm] + 132
17  MyApp                               0x0000000100271f74 +[MYDataStore setupStore] + 772
18  MyApp                               0x00000001001dae14 -[MYDirector init] + 144
19  MyApp                               0x00000001001dad3c __28+[MYDirector sharedDirector]_block_invoke + 60
20  libdispatch.dylib                   0x0000000101a8d21c _dispatch_client_callout + 16
21  libdispatch.dylib                   0x0000000101a8e04c dispatch_once_f + 116
22  MyApp                               0x00000001001dacdc +[MYDirector sharedDirector] + 144
23  MyApp                               0x00000001000ef86c -[AppDelegate application:didFinishLaunchingWithOptions:] + 724
24  UIKit                               0x000000018b77c100 <redacted> + 400
25  UIKit                               0x000000018b98c858 <redacted> + 3524
26  UIKit                               0x000000018b9925c8 <redacted> + 1656
27  UIKit                               0x000000018b9a6e60 <redacted> + 48
28  UIKit                               0x000000018b98f5ac <redacted> + 168
29  FrontBoardServices                  0x000000018745d8bc <redacted> + 36
30  FrontBoardServices                  0x000000018745d728 <redacted> + 176
31  FrontBoardServices                  0x000000018745dad0 <redacted> + 56
32  CoreFoundation                      0x0000000185864278 <redacted> + 24
33  CoreFoundation                      0x0000000185863bc0 <redacted> + 524
34  CoreFoundation                      0x00000001858617c0 <redacted> + 804
35  CoreFoundation                      0x0000000185790048 CFRunLoopRunSpecific + 444
36  UIKit                               0x000000018b7752b0 <redacted> + 608
37  UIKit                               0x000000018b770034 UIApplicationMain + 208
38  MyApp                               0x00000001000e4154 main + 124
39  libdyld.dylib                       0x00000001847745b8 <redacted> + 4
IMPORTANT: if you see this error, please send this log to help@realm.io.(lldb) 
finnschiermer commented 7 years ago

Same as https://github.com/realm/realm-core/issues/2673

finnschiermer commented 7 years ago

The second stack trace matches #2673, but the first does not.

reggian commented 7 years ago

@finnschiermer If you need any additional info I will be happy to assist.

finnschiermer commented 7 years ago

Any idea if the users experiencing this problem have something in common? Android versions? 32 vs 64 bit Hardware?

reggian commented 7 years ago

They all seem to be iOS 10.x on 64-bit HW.

finnschiermer commented 7 years ago

@Reggian Earlier you wrote: "I have managed to obtain the realm db file from one of the crashing apps but when swapping the container with the obtained db the app on my phone launches without crashing."

Question 1: What does the word "container" refer to in this context? Question 2: Do I understand you correctly, that the same realm file will consistently crash the app when opened on one device, but not when opened on another?

reggian commented 7 years ago

On iOS I can replace the app "container", that means all data crated with the app (e.g. realm file, other temporary files etc.) So I have replaced the realm file my app created on my phone with the one I have managed to obtain from one of the users experiencing the crash.

After doing so my app did not crash the first time around. When I repeated the procedure with a file from another user experiencing the crash my app crashed on every launch with the second stack trace posted in the original post.

reggian commented 7 years ago

Aha I see what is the cause of the misinterpretations.

Crashlytics has a strange grouping mechanism. They have grouped all realm crashes that crash on the line realm::util::terminate(char const*, char const*, long) together, regardless of the stack trace... This is probably why the realm file from the first user did not crash my app and the one from the second user did. This also explains your post:

The second stack trace matches #2673, but the first does not.

I am sorry I did not notice this sooner.

finnschiermer commented 7 years ago

@Reggian Are you willing to share the realm file with us? Perhaps I can get something out of it. Perhaps not.

reggian commented 7 years ago

@finnschiermer Unfortunately I can not since our user's data is in it. I can however send you Realm Browser crash logs (when opening those realm files). If you have some instructions on how to obfuscate the user's data we should get in touch on a private channel.

finnschiermer commented 7 years ago

@Reggian I'm sorry, but there is no safe way to obfuscate the users data while still allowing me full access to the relevant meta-data. I also won't get anything from the Realm Browser :-(.

sochalewski commented 6 years ago

@finnschiermer The same story comes here: https://github.com/realm/realm-cocoa/issues/5617 Do you know something new about this?

bmunkholm commented 6 years ago

The core version used here is very old. Closing as there is no more new information to gather from this.