Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realm.init crash on realm->_realm = Realm::get_shared_realm(config); #5937

Closed
michalrentka opened this issue Oct 12, 2022 · 18 comments
Closed

Comments

@michalrentka
Copy link

SDK and version

SDK: Realm-Swift
Version: 10.32.0
Core: realm-core-12.9.0

Observations

User reported a startup crash in their app. I'm including their DB files in a comment below. I can reproduce the issue in the app when I replace my db files with theirs.

The crash happens when I try to perform a write soon after app launch: https://github.com/zotero/zotero-ios/blob/90c7c31c806b80ed2b1375f9f79910f4f5e20f64/Zotero/Controllers/Controllers.swift#L315-L318.
Above lines run this code: https://github.com/zotero/zotero-ios/blob/90c7c31c806b80ed2b1375f9f79910f4f5e20f64/Zotero/Controllers/Database/RealmDbStorage.swift#L57-L62.
And the RealmDbCoordinator pretty much just initialises Realm instance with given config: https://github.com/zotero/zotero-ios/blob/90c7c31c806b80ed2b1375f9f79910f4f5e20f64/Zotero/Controllers/Database/RealmDbStorage.swift#L114-L117.

So to sum it up, it crashes on first initialisation of Realm instance which happens after app launch. Realm is not accessed anywhere else before this, no reads or writes.

Crash log / stacktrace

Crash log from the user:

Incident Identifier: 3C201680-AF10-4955-8D9A-FA89C9FDEE65
Hardware Model:      iPad13,8
Process:         Zotero [3213]
Path:            /private/var/containers/Bundle/Application/26D2D3C0-D8FB-416E-8DC7-34E323F50C0E/Zotero.app/Zotero
Identifier:      org.zotero.ios.Zotero
Version:         1.0.4 (19)
Code Type:       ARM-64
Parent Process:   [1]

Date/Time:       2022-10-10 16:11:51 +0000
OS Version:      iPhone OS 15.6.1 (19G82)
Report Version:  104

Exception Type:  SIGABRT
Exception Codes: #0 at 0x1b73a1b38
Crashed Thread:  0

Thread 0 Crashed:
0   libsystem_kernel.dylib              0x00000001b73a1b38 __pthread_kill + 8
1   libsystem_c.dylib                   0x000000018b578524 abort + 168
2   Zotero                              0x00000001013222d0 realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) + 11051728 (terminate.cpp:147)
3   Zotero                              0x0000000101322610 realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 11052560 (terminate.cpp:142)
4   Zotero                              0x000000010132238c realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) + 11051916 (terminate.cpp:0)
5   Zotero                              0x00000001010cc300 realm::Cluster::init(realm::MemRef) + 8602368 (cluster.cpp:210)
6   Zotero                              0x00000001010db99c realm::ClusterTree::create_root_from_parent(realm::ArrayParent*, unsigned long) + 8665500 (cluster_tree.cpp:813)
7   Zotero                              0x00000001010dbc8c realm::ClusterTree::init_from_parent() + 8666252 (cluster_tree.cpp:864)
8   Zotero                              0x00000001012dd88c realm::Table::init(unsigned long, realm::ArrayParent*, unsigned long, bool, bool) + 10770572 (table.cpp:616)
9   Zotero                              0x00000001010f4dc8 realm::Group::create_table_accessor(unsigned long) + 8768968 (group.cpp:795)
10  Zotero                              0x00000001010f4a5c realm::Group::do_get_table(unsigned long) + 8768092 (group.cpp:0)
11  Zotero                              0x00000001012fa418 realm::Transaction::check_consistency() + 10888216 (transaction.cpp:0)
12  Zotero                              0x00000001010de8c8 realm::DB::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, realm::DBOptions) + 8677576 (db.cpp:1168)
13  Zotero                              0x00000001010e0c1c realm::DB::open(realm::Replication&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, realm::DBOptions) + 8686620 (db.cpp:1203)
14  Zotero                              0x00000001010e492c realm::DB::create(std::__1::unique_ptr<realm::Replication, std::__1::default_delete<realm::Replication> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, realm::DBOptions) + 8702252 (db.cpp:2517)
15  Zotero                              0x000000010116fac0 realm::_impl::RealmCoordinator::open_db() + 9272000 (realm_coordinator.cpp:519)
16  Zotero                              0x00000001011709ac realm::_impl::RealmCoordinator::do_get_realm(realm::RealmConfig, std::__1::shared_ptr<realm::Realm>&, std::__1::optional<realm::VersionID>, realm::util::CheckedUniqueLock&) + 9275820 (realm_coordinator.cpp:309)
17  Zotero                              0x000000010117083c realm::_impl::RealmCoordinator::get_realm(realm::RealmConfig, std::__1::optional<realm::VersionID>) + 9275452 (realm_coordinator.cpp:279)
18  Zotero                              0x00000001011ce918 realm::Realm::get_shared_realm(realm::RealmConfig) + 9660696 (shared_realm.cpp:157)
19  Zotero                              0x0000000100fe15dc +[RLMRealm realmWithConfiguration:queue:error:] + 7640540 (RLMRealm.mm:532)
20  Zotero                              0x0000000101079348 @nonobjc RLMRealm.__allocating_init(configuration:queue:) + 8262472 (<compiler-generated>:0)
21  Zotero                              0x0000000101079858 Realm.init(configuration:queue:) + 8263768 (Realm.swift:95)
22  Zotero                              0x0000000100a5e09c UserControllers.init(userId:controllers:) + 1859740 (Controllers.swift:315)
23  Zotero                              0x0000000100a5d010 Controllers.set(sessionData:isLogin:debugLogging:) + 1855504 (Controllers.swift:212)
24  Zotero                              0x0000000100a5ba8c Controllers.initializeSessionIfPossible(failOnError:) + 1849996 (Controllers.swift:139)
25  Zotero                              0x0000000100a5b620 closure #1 in Controllers.init() + 1848864 (<compiler-generated>:0)
26  Zotero                              0x00000001009ff804 partial apply for closure #2 in AppCoordinator.report(id:completion:) + 1472516 (<compiler-generated>:0)
27  Zotero                              0x0000000100baf79c thunk for @escaping @callee_guaranteed (@guaranteed UIAlertAction) -> () + 3241884 (<compiler-generated>:0)
28  UIKitCore                           0x000000018299fc54 -[UIAlertController _invokeHandlersForAction:] + 116
29  UIKitCore                           0x0000000182f74cd0 __103-[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:dismissCompletion:]_block_invoke.469 + 36
30  UIKitCore                           0x0000000182bf0ff0 -[UIPresentationController transitionDidFinish:] + 1284
31  UIKitCore                           0x000000018313ae50 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke.461 + 212
32  UIKitCore                           0x0000000182a8a450 -[_UIViewControllerTransitionContext completeTransition:] + 124
33  UIKitCore                           0x0000000183af54dc __UIVIEW_IS_EXECUTING_ANIMATION_COMPLETION_BLOCK__ + 36
34  UIKitCore                           0x0000000182b0dfa4 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 728
35  UIKitCore                           0x00000001829d9d04 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 248
36  UIKitCore                           0x00000001829ee504 -[UIViewAnimationState animationDidStop:finished:] + 244
37  UIKitCore                           0x00000001829ee66c -[UIViewAnimationState animationDidStop:finished:] + 604
38  QuartzCore                          0x00000001841dae50 CA::Layer::run_animation_callbacks+ 835152 (void*) + 280
39  libdispatch.dylib                   0x00000001800cda30 _dispatch_client_callout + 20
40  libdispatch.dylib                   0x00000001800dbf48 _dispatch_main_queue_drain + 928
41  libdispatch.dylib                   0x00000001800dbb98 _dispatch_main_queue_callback_4CF + 44
42  CoreFoundation                      0x000000018041e800 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
43  CoreFoundation                      0x00000001803d8704 __CFRunLoopRun + 2532
44  CoreFoundation                      0x00000001803ebbc8 CFRunLoopRunSpecific + 600
45  GraphicsServices                    0x000000019c557374 GSEventRunModal + 164
46  UIKitCore                           0x0000000182d5fb58 -[UIApplication _run] + 1100
47  UIKitCore                           0x0000000182ae1090 UIApplicationMain + 364
48  Zotero                              0x000000010089c510 main + 17680 (<compiler-generated>:0)
49  ???                                 0x0000000101aa5da4 0x0 + 0

Thread 1:
0   libsystem_kernel.dylib              0x00000001b739ba74 __workq_kernreturn + 8
1   libsystem_pthread.dylib             0x00000001f0b58e5c start_wqthread + 8

Thread 2:
0   libsystem_kernel.dylib              0x00000001b739bf24 __psynch_cvwait + 8
1   Foundation                          0x0000000181c849e4 -[NSOperation waitUntilFinished] + 580
2   CoreFoundation                      0x000000018040d8fc _CFXNotificationPost + 808
3   Foundation                          0x0000000181be0734 -[NSNotificationCenter postNotificationName:object:userInfo:] + 96
4   Pasteboard                          0x00000001e268cd2c __67+[PBServerConnection beginListeningToPasteboardChangeNotifications]_block_invoke_2 + 204
5   libsystem_notify.dylib              0x00000001a05753b0 0x1a0572000 + 13232
6   libdispatch.dylib                   0x00000001800dc830 _dispatch_block_async_invoke2 + 148
7   libdispatch.dylib                   0x00000001800cda30 _dispatch_client_callout + 20
8   libdispatch.dylib                   0x00000001800d5124 _dispatch_lane_serial_drain + 668
9   libdispatch.dylib                   0x00000001800d5c80 _dispatch_lane_invoke + 392
10  libdispatch.dylib                   0x00000001800e0500 _dispatch_workloop_worker_thread + 648
11  libsystem_pthread.dylib             0x00000001f0b590bc _pthread_wqthread + 288
12  libsystem_pthread.dylib             0x00000001f0b58e5c start_wqthread + 8

Thread 3:
0   libsystem_kernel.dylib              0x00000001b739ba74 __workq_kernreturn + 8
1   libsystem_pthread.dylib             0x00000001f0b58e5c start_wqthread + 8

Thread 4:
0   libsystem_kernel.dylib              0x00000001b739b4a0 mach_msg_trap + 8
1   CoreFoundation                      0x00000001803d3d30 __CFRunLoopServiceMachPort + 372
2   CoreFoundation                      0x00000001803d81bc __CFRunLoopRun + 1180
3   CoreFoundation                      0x00000001803ebbc8 CFRunLoopRunSpecific + 600
4   Foundation                          0x0000000181bde444 -[NSRunLoop+ 103492 (NSRunLoop) runMode:beforeDate:] + 236
5   Foundation                          0x0000000181c1fe0c -[NSRunLoop+ 372236 (NSRunLoop) runUntilDate:] + 92
6   UIKitCore                           0x0000000182cd9cc4 -[UIEventFetcher threadMain] + 524
7   Foundation                          0x0000000181c2e41c __NSThread__start__ + 808
8   libsystem_pthread.dylib             0x00000001f0b599ac _pthread_start + 148
9   libsystem_pthread.dylib             0x00000001f0b58e68 thread_start + 8

Thread 5:
0   ???                                 0x0000000000000000 0x0 + 0

Thread 6:
0   libsystem_kernel.dylib              0x00000001b739b4a0 mach_msg_trap + 8
1   Zotero                              0x0000000101354f2c exception_server_thread + 11259692 (PLCrashMachExceptionServer.m:683)
2   libsystem_pthread.dylib             0x00000001f0b599ac _pthread_start + 148
3   libsystem_pthread.dylib             0x00000001f0b58e68 thread_start + 8

Thread 7:
0   libsystem_kernel.dylib              0x00000001b739b4a0 mach_msg_trap + 8
1   CoreFoundation                      0x00000001803d3d30 __CFRunLoopServiceMachPort + 372
2   CoreFoundation                      0x00000001803d81bc __CFRunLoopRun + 1180
3   CoreFoundation                      0x00000001803ebbc8 CFRunLoopRunSpecific + 600
4   CFNetwork                           0x0000000180e681dc 0x180bf0000 + 2589148
5   Foundation                          0x0000000181c2e41c __NSThread__start__ + 808
6   libsystem_pthread.dylib             0x00000001f0b599ac _pthread_start + 148
7   libsystem_pthread.dylib             0x00000001f0b58e68 thread_start + 8

Thread 0 crashed with ARM-64 Thread State:
    pc: 0x00000001b73a1b38     fp: 0x000000016f5641f0     sp: 0x000000016f5641d0     x0: 0x0000000000000000 
    x1: 0x0000000000000000     x2: 0x0000000000000000     x3: 0x0000000000000000     x4: 0x000000000000000e 
    x5: 0x000000012a039000     x6: 0x0000000000001c00     x7: 0x0000000000000000     x8: 0x6966ffdd2bee53ab 
    x9: 0x6966ffdc2a41d62b    x10: 0x0000000000716400    x11: 0x0000000000bf3d01    x12: 0x0000000000004009 
   x13: 0x000000012a038000    x14: 0x0000000000003fff    x15: 0x0000000000000e49    x16: 0x0000000000000148 
   x17: 0x0000000101af8580    x18: 0x0000000000000000    x19: 0x0000000000000006    x20: 0x0000000000000103 
   x21: 0x0000000101af8660    x22: 0x000000016f5642b0    x23: 0x00000001013eb6e4    x24: 0x00000001116bce98 
   x25: 0x0000000283772840    x26: 0x000000012a026400    x27: 0x0000000101723000    x28: 0x0000000000000000 
    lr: 0x00000001f0b5f3bc   cpsr: 0x0000000040001000 

Binary Images: ...

My stack trace from simulator:

/Users/michalrentka/Library/Developer/Xcode/DerivedData/Zotero-evagswpzgkjzxbfkkfpwmjrlojxe/SourcePackages/checkouts/realm-core/src/realm/array.hpp:754: [realm-core-12.9.0] Assertion failed: has_refs()
0   Zotero                              0x000000010cc9a68c _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   Zotero                              0x000000010cc9a52e _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 238
2   Zotero                              0x000000010c3f34dc _ZNK5realm5Array20get_as_ref_or_taggedEm + 92
3   Zotero                              0x000000010c3f3426 _ZN5realm7Cluster4initENS_6MemRefE + 70
4   Zotero                              0x000000010c41eafb _ZN5realm11ClusterTree23create_root_from_parentEPNS_11ArrayParentEm + 587
5   Zotero                              0x000000010cbe767b _ZN5realm16TableClusterTree20get_root_from_parentEv + 107
6   Zotero                              0x000000010c41f2de _ZN5realm11ClusterTree16init_from_parentEv + 30
7   Zotero                              0x000000010cba4317 _ZN5realm5Table4initEmPNS_11ArrayParentEmbb + 503
8   Zotero                              0x000000010c466e19 _ZN5realm5Group21create_table_accessorEm + 1113
9   Zotero                              0x000000010c46693b _ZN5realm5Group12do_get_tableEm + 251
10  Zotero                              0x000000010c4004ab _ZN5realm5Group9get_tableENS_8TableKeyE + 155
11  Zotero                              0x000000010cbfdd98 _ZN5realm11Transaction17check_consistencyEv + 216
12  Zotero                              0x000000010c429c03 _ZN5realm2DB4openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbNS_9DBOptionsE + 11267
13  Zotero                              0x000000010c42bc9e _ZN5realm2DB4openERNS_11ReplicationERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEENS_9DBOptionsE + 286
14  Zotero                              0x000000010c4328e3 _ZN5realm2DB6createENSt3__110unique_ptrINS_11ReplicationENS1_14default_deleteIS3_EEEERKNS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS_9DBOptionsE + 419
15  Zotero                              0x000000010c60115c _ZN5realm5_impl16RealmCoordinator7open_dbEv + 1692
16  Zotero                              0x000000010c602a43 _ZN5realm5_impl16RealmCoordinator12do_get_realmENS_11RealmConfigERNSt3__110shared_ptrINS_5RealmEEENS3_8optionalINS_9VersionIDEEERNS_4util17CheckedUniqueLockE + 83
17  Zotero                              0x000000010c602873 _ZN5realm5_impl16RealmCoordinator9get_realmENS_11RealmConfigENSt3__18optionalINS_9VersionIDEEE + 899
18  Zotero                              0x000000010c765fe8 _ZN5realm5Realm16get_shared_realmENS_11RealmConfigE + 216
19  Zotero                              0x000000010c15c4e3 +[RLMRealm realmWithConfiguration:queue:error:] + 995
20  Zotero                              0x000000010c218af2 $sSo8RLMRealmC13configuration5queueABSo0A13ConfigurationC_So012OS_dispatch_C0CSgtKcfCTO + 146
21  Zotero                              0x000000010c2db333 $s10RealmSwift0A0V13configuration5queueA2C13ConfigurationV_So012OS_dispatch_D0CSgtKcfC + 195
22  Zotero                              0x000000010b7269e6 $s6Zotero18RealmDbCoordinatorV13configuration5queueAC0B5Swift0B0V13ConfigurationV_So012OS_dispatch_F0CtKcfC + 326
23  Zotero                              0x000000010b72675a $s6Zotero14RealmDbStorageC7perform2on4withySo17OS_dispatch_queueC_yAA0C11Coordinator_pKXEtKFyyKXEfU_ + 218
24  Zotero                              0x000000010b72688c $s6Zotero14RealmDbStorageC7perform2on4withySo17OS_dispatch_queueC_yAA0C11Coordinator_pKXEtKFyyKXEfU_TA + 28
25  Zotero                              0x000000010b7263c0 $s6Zotero14RealmDbStorageC32performInAutoreleasepoolIfNeeded33_0C0F801E5634ADE4DF1A4E8CD0CAA38DLL8invokingxxyKXE_tKlF + 144
26  Zotero                              0x000000010b7265f8 $s6Zotero14RealmDbStorageC7perform2on4withySo17OS_dispatch_queueC_yAA0C11Coordinator_pKXEtKF + 168
27  Zotero                              0x000000010b728bfd $s6Zotero14RealmDbStorageCAA0cD0A2aDP7perform2on4withySo17OS_dispatch_queueC_yAA0C11Coordinator_pKXEtKFTW + 13
28  Zotero                              0x000000010b6553d6 $s6Zotero15UserControllersC6userId11controllersACSi_AA0C0CtKcfc + 1750
29  Zotero                              0x000000010b654804 $s6Zotero15UserControllersC6userId11controllersACSi_AA0C0CtKcfC + 68
30  Zotero                              0x000000010b653a81 $s6Zotero11ControllersC3set33_B4B29AEF0E8AB03860939ABD882DAE9ALL11sessionData7isLogin12debugLoggingySi6userId_SS8apiTokent_SbAA05DebugP0CtF + 401
31  Zotero                              0x000000010b65281f $s6Zotero11ControllersC6update33_B4B29AEF0E8AB03860939ABD882DAE9ALL4with7isLogin12debugLoggingySi6userId_SS8apiTokentSg_SbAA05DebugO0CtF + 367
32  Zotero                              0x000000010b6511c1 $s6Zotero11ControllersC27initializeSessionIfPossible33_B4B29AEF0E8AB03860939ABD882DAE9ALL11failOnErrorySb_tF + 241
33  Zotero                              0x000000010b650d60 $s6Zotero11ControllersCACycfcyycfU_ + 176
34  Zotero                              0x000000010b954a02 $s6Zotero13CrashReporterC21processPendingReports10completionyyyc_tFyycfU_yycfU_ + 50
35  Zotero                              0x000000010b70e472 $s6Zotero12inMainThread4sync6actionySb_yyctFyyScMYccfU0_ + 50
36  Zotero                              0x000000010b328818 $sIeg_IeyB_TR + 40
37  libdispatch.dylib                   0x000000011aab7d18 _dispatch_call_block_and_release + 12
38  libdispatch.dylib                   0x000000011aab8f5b _dispatch_client_callout + 8
39  libdispatch.dylib                   0x000000011aac9d55 _dispatch_main_queue_drain + 1463
40  libdispatch.dylib                   0x000000011aac9790 _dispatch_main_queue_callback_4CF + 31
41  CoreFoundation                      0x000000011896c9f7 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
42  CoreFoundation                      0x00000001189673c6 __CFRunLoopRun + 2482
43  CoreFoundation                      0x0000000118966637 CFRunLoopRunSpecific + 560
44  GraphicsServices                    0x000000011b35b28a GSEventRunModal + 139
45  UIKitCore                           0x0000000141299425 -[UIApplication _run] + 994
46  UIKitCore                           0x000000014129e301 UIApplicationMain + 123
47  Zotero                              0x000000010b4f4d96 main + 502
48  dyld                                0x000000011175c2bf start_sim + 10
49  ???                                 0x000000011777c52e 0x0 + 4688692526!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose

Steps & Code to Reproduce

  1. Download app from https://github.com/zotero/zotero-ios
  2. Download realm files from below comment
  3. Run the app on iPad / iPhone simulator
  4. Create free Zotero account and log in with it (or contact me, I'll send you test account privately)
  5. Replace original db files with downloaded realm files
  6. Start the app - crash on launch
@michalrentka
Copy link
Author

db.zip

@finnschiermer
Copy link
Contributor

Potential duplicate of #5808

@NZQN23
Copy link

NZQN23 commented Oct 17, 2022

I also experience these crashes in my app.

0   libsystem_kernel.dylib        	0x0000000205f8a200 __pthread_kill + 8
1   libsystem_pthread.dylib       	0x00000002161c71ac pthread_kill + 268 (pthread.c:1670)
2   libsystem_c.dylib             	0x00000001d0d81ca0 abort + 180 (abort.c:118)
3   Realm                         	0x00000001032eb8e4 please_report_this_issue_in_github_realm_realm_core_v_12_9_0 + 12
4   Realm                         	0x00000001032ebbcc realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 260
5   Realm                         	0x00000001032eba2c realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) + 328
6   Realm                         	0x000000010318fc28 realm::Cluster::init(realm::MemRef) + 296
7   Realm                         	0x00000001031a060c realm::ClusterTree::create_root_from_parent(realm::ArrayParent*, unsigned long) + 500
8   Realm                         	0x00000001031a0934 realm::ClusterTree::init_from_parent() + 36
9   Realm                         	0x000000010329a468 realm::Table::init(unsigned long, realm::ArrayParent*, unsigned long, bool, bool) + 200
10  Realm                         	0x00000001031bde80 realm::Group::create_table_accessor(unsigned long) + 812
11  Realm                         	0x00000001031bdafc realm::Group::do_get_table(unsigned long) + 96
12  Realm                         	0x00000001032c5110 realm::Transaction::check_consistency() + 124
13  Realm                         	0x00000001031a3fc4 realm::DB::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, realm::DBOptions) + 3312
14  Realm                         	0x00000001031a69c0 realm::DB::open(realm::Replication&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, realm::DBOptions) + 124
15  Realm                         	0x00000001031ab0cc realm::DB::create(std::__1::unique_ptr<realm::Replication, std::__1::default_delete<realm::Replication> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > cons... + 156
16  Realm                         	0x00000001033d33ac realm::_impl::RealmCoordinator::open_db() + 1216
17  Realm                         	0x00000001033d4220 realm::_impl::RealmCoordinator::do_get_realm(realm::RealmConfig, std::__1::shared_ptr<realm::Realm>&, std::__1::optional<realm::VersionID>, realm::util::CheckedUniqueLock&) + 72
18  Realm                         	0x00000001033d408c realm::_impl::RealmCoordinator::get_realm(realm::RealmConfig, std::__1::optional<realm::VersionID>) + 380
19  Realm                         	0x00000001034623c0 realm::Realm::get_shared_realm(realm::RealmConfig) + 120
20  Realm                         	0x000000010313d99c +[RLMRealm realmWithConfiguration:queue:error:] + 960 (RLMRealm.mm:532)
21  RealmSwift                    	0x0000000103abd6bc @nonobjc RLMRealm.__allocating_init(configuration:queue:) + 72 (<compiler-generated>:0)
22  RealmSwift                    	0x0000000103abdba8 Realm.init(configuration:queue:) + 100 (Realm.swift:95)
23  Geory                         	0x0000000102bdb4c8 closure #1 in closure #1 in initializeDatabase(qos:shouldMigrate:shouldCompact:completion:) + 580 (DatabaseManagement.swift:173)
24  Geory                         	0x0000000102bdd95c specialized autoreleasepool<A>(invoking:) + 32 (DatabaseManagement.swift:134)
25  Geory                         	0x0000000102bdd95c closure #1 in initializeDatabase(qos:shouldMigrate:shouldCompact:completion:) + 32 (<compiler-generated>:0)
26  Geory                         	0x0000000102bdd95c partial apply for closure #1 in initializeDatabase(qos:shouldMigrate:shouldCompact:completion:) + 68
27  Geory                         	0x0000000102b759a0 thunk for @escaping @callee_guaranteed () -> () + 28 (<compiler-generated>:0)
28  libdispatch.dylib             	0x00000001d0d1c4b4 _dispatch_call_block_and_release + 32 (init.c:1518)
29  libdispatch.dylib             	0x00000001d0d1dfdc _dispatch_client_callout + 20 (object.m:560)
30  libdispatch.dylib             	0x00000001d0d2fb8c _dispatch_root_queue_drain + 684 (inline_internal.h:2632)
31  libdispatch.dylib             	0x00000001d0d30284 _dispatch_worker_thread2 + 164 (queue.c:7052)
32  libsystem_pthread.dylib       	0x00000002161c0dbc _pthread_wqthread + 228 (pthread.c:2631)
33  libsystem_pthread.dylib       	0x00000002161c0b98 start_wqthread + 8

@sedwo
Copy link

sedwo commented Oct 17, 2022

I currently also get this crash to occur every time with my specific realm DB file from a client.

Runtime: iOS 16.0 (20A360) - DeviceType: iPad mini (6th generation)
Occurs on real device and simulator.

  - Realm (10.31.0):
    - Realm/Headers (= 10.31.0)
  - Realm/Headers (10.31.0)
  - RealmSwift (10.31.0):
    - Realm (= 10.31.0)

Seems to crash internally when I call Realm(configuration: realmConfig)

[realm-core-11.15.0] Assertion failed: top_size > 2 && top_size <= 6

Release crash info:

Crashed: com.apple.main-thread
0  libsystem_kernel.dylib         0x7b38 __pthread_kill + 8
1  libsystem_pthread.dylib        0x73bc pthread_kill + 268
2  libsystem_c.dylib              0x20524 abort + 168
3  Realm                          0x2d6d44 please_report_this_issue_in_github_realm_realm_core_v_12_9_0 + 10
4  Realm                          0x2d702c realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 260
5  Realm                          0x2d6e8c realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) + 328
6  Realm                          0x2857fc realm::Table::get_key_direct(realm::Allocator&, unsigned long) + 180
7  Realm                          0x1a74c8 realm::TableKeyIterator::load_key() + 180
8  Realm                          0x1a7514 realm::TableKeyIterator::operator*() + 36
9  Realm                          0x2b054c realm::Transaction::check_consistency() + 88
10 Realm                          0x18fd6c realm::DB::open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, realm::DBOptions) + 3312
11 Realm                          0x192768 realm::DB::open(realm::Replication&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, realm::DBOptions) + 124
12 Realm                          0x196e74 realm::DB::create(std::__1::unique_ptr<realm::Replication, std::__1::default_delete<realm::Replication> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, realm::DBOptions) + 156
13 Realm                          0x3be80c realm::_impl::RealmCoordinator::open_db() + 1216
14 Realm                          0x3bf680 realm::_impl::RealmCoordinator::do_get_realm(realm::RealmConfig, std::__1::shared_ptr<realm::Realm>&, std::__1::optional<realm::VersionID>, realm::util::CheckedUniqueLock&) + 72
15 Realm                          0x3bf4ec realm::_impl::RealmCoordinator::get_realm(realm::RealmConfig, std::__1::optional<realm::VersionID>) + 380
16 Realm                          0x44d820 realm::Realm::get_shared_realm(realm::RealmConfig) + 120
17 Realm                          0x1271b0 +[RLMRealm realmWithConfiguration:queue:error:] + 1024
18 RealmSwift                     0x6e8dc $sSo8RLMRealmC13configuration5queueABSo0A13ConfigurationC_So012OS_dispatch_C0CSgtKcfCTO + 72
19 RealmSwift                     0x6edec $s10RealmSwift0A0V13configuration5queueA2C13ConfigurationV_So012OS_dispatch_D0CSgtKcfC + 104

MongoDB Realm Studio seems to freeze on a gray screen as well when trying to view the DB file.

Debug crash info.

/Users/realm/workspace/realm_realm-core_release_12.9.0/src/realm/array.hpp:754: [realm-core-12.9.0] Assertion failed: has_refs()
0   Realm                               0x00000001074a20ac _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   Realm                               0x00000001074a1ff4 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 328
2   Realm                               0x0000000107450ea0 _ZN5realm5Table14get_key_directERNS_9AllocatorEm + 180
3   Realm                               0x0000000107373234 _ZN5realm16TableKeyIterator8load_keyEv + 180
4   Realm                               0x0000000107373280 _ZN5realm16TableKeyIteratordeEv + 36
5   Realm                               0x000000010747bb38 _ZN5realm11Transaction17check_consistencyEv + 88
6   Realm                               0x000000010735c03c _ZN5realm2DB4openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbNS_9DBOptionsE + 3240
7   Realm                               0x000000010735e990 _ZN5realm2DB4openERNS_11ReplicationERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEENS_9DBOptionsE + 124
8   Realm                               0x0000000107362d08 _ZN5realm2DB6createENSt3__110unique_ptrINS_11ReplicationENS1_14default_deleteIS3_EEEERKNS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS_9DBOptionsE + 156
9   Realm                               0x0000000107588cbc _ZN5realm5_impl16RealmCoordinator7open_dbEv + 1160
10  Realm                               0x0000000107589aa8 _ZN5realm5_impl16RealmCoordinator12do_get_realmENS_11RealmConfigERNSt3__110shared_ptrINS_5RealmEEENS3_8optionalINS_9VersionIDEEERNS_4util17CheckedUniqueLockE + 72
11  Realm                               0x000000010758992c _ZN5realm5_impl16RealmCoordinator9get_realmENS_11RealmConfigENSt3__18optionalINS_9VersionIDEEE + 372
12  Realm                               0x000000010761701c _ZN5realm5Realm16get_shared_realmENS_11RealmConfigE + 120
13  Realm                               0x00000001072f35fc +[RLMRealm realmWithConfiguration:queue:error:] + 1016
14  RealmSwift                          0x0000000106b9c388 $sSo8RLMRealmC13configuration5queueABSo0A13ConfigurationC_So012OS_dispatch_C0CSgtKcfCTO + 72
15  RealmSwift                          0x0000000106b9c898 $s10RealmSwift0A0V13configuration5queueA2C13ConfigurationV_So012OS_dispatch_D0CSgtKcfC + 104

60  ???                                 0x951e000000000000 0x0 + 10745025760952582144!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose2022-10-07 18:13:13.110807-0400 SignAgent[73941:27705326] /Users/realm/workspace/realm_realm-core_release_12.9.0/src/realm/array.hpp:754: [realm-core-12.9.0] Assertion failed: has_refs()
0   Realm                               0x00000001074a20ac _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1   Realm                               0x00000001074a1ff4 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 328
2   Realm                               0x0000000107450ea0 _ZN5realm5Table14get_key_directERNS_9AllocatorEm + 180
3   Realm                               0x0000000107373234 _ZN5realm16TableKeyIterator8load_keyEv + 180
4   Realm                               0x0000000107373280 _ZN5realm16TableKeyIteratordeEv + 36
5   Realm                               0x000000010747bb38 _ZN5realm11Transaction17check_consistencyEv + 88
6   Realm                               0x000000010735c03c _ZN5realm2DB4openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbNS_9DBOptionsE + 3240
7   Realm                               0x000000010735e990 _ZN5realm2DB4openERNS_11ReplicationERKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEENS_9DBOptionsE + 124
8   Realm                               0x0000000107362d08 _ZN5realm2DB6createENSt3__110unique_ptrINS_11ReplicationENS1_14default_deleteIS3_EEEERKNS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS_9DBOptionsE + 156
9   Realm                               0x0000000107588cbc _ZN5realm5_impl16RealmCoordinator7open_dbEv + 1160
10  Realm                               0x0000000107589aa8 _ZN5realm5_impl16RealmCoordinator12do_get_realmENS_11RealmConfigERNSt3__110shared_ptrINS_5RealmEEENS3_8optionalINS_9VersionIDEEERNS_4util17CheckedUniqueLockE + 72
11  Realm                               0x000000010758992c _ZN5realm5_impl16RealmCoordinator9get_realmENS_11RealmConfigENSt3__18optionalINS_9VersionIDEEE + 372
12  Realm                               0x000000010761701c _ZN5realm5Realm16get_shared_realmENS_11RealmConfigE + 120
13  Realm                               0x00000001072f35fc +[RLMRealm realmWithConfiguration:queue:error:] + 1016
14  RealmSwift                          0x0000000106b9c388 $sSo8RLMRealmC13configuration5queueABSo0A13ConfigurationC_So012OS_dispatch_C0CSgtKcfCTO + 72
15  RealmSwift                          0x0000000106b9c898 $s10RealmSwift0A0V13configuration5queueA2C13ConfigurationV_So012OS_dispatch_D0CSgtKcfC + 104

58  dyld                                0x0000000104d55fa0 start_sim + 20
59  ???                                 0x0000000104ef108c 0x0 + 4377743500
60  ???                                 0x951e000000000000 0x0 + 10745025760952582144!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose
CoreSimulator 857.7 - Device: iPad mini (6th generation) (7B47FE55-4233-411A-9804-BCF6D1059AB4) - Runtime: iOS 16.0 (20A360) - DeviceType: iPad mini (6th generation)
(lldb) 

Re-tested on v10.32.0. Hard crash still occurs.

(lldb) po config
▿ Realm.Configuration {
	fileURL = .../********.realm;
	inMemoryIdentifier = (null);
	encryptionKey = (null);
	readOnly = 0;
	schemaVersion = 3;
	migrationBlock = <__NSMallocBlock__: 0x6000028fc990>;
	deleteRealmIfMigrationNeeded = 0;
	shouldCompactOnLaunch = <__NSMallocBlock__: 0x6000028fcc60>;
	dynamic = 0;
	customSchema = (null);
}
  - _syncConfiguration : nil
  ▿ _path : Optional<String>
    - some : ".../********.realm;"
  - _inMemoryIdentifier : nil
  - encryptionKey : nil
  - readOnly : false
  - schemaVersion : 3
  ▿ migrationBlock : Optional<(Migration, UInt64) -> ()>
    - some : (Function)
  - _deleteRealmIfMigrationNeeded : false
  ▿ shouldCompactOnLaunch : Optional<(Int, Int) -> Bool>
    - some : (Function)
  - maximumNumberOfActiveVersions : nil
  - seedFilePath : nil
  - eventConfiguration : nil
  - customSchema : nil
  - disableFormatUpgrade : false
  - initialSubscriptions : nil
  - rerunOnOpen : false

(lldb) 

I can also supply the .realm file for your investigation.

image

@jedelbo
Copy link
Contributor

jedelbo commented Oct 19, 2022

@sedwo We would very much appreciate if you could share the realm file with us. Please send to realm-help@mongodb.com

@sedwo
Copy link

sedwo commented Oct 19, 2022

@jedelbo sent! 👍

@jedelbo
Copy link
Contributor

jedelbo commented Oct 19, 2022

@sedwo thanks!

@sedwo
Copy link

sedwo commented Oct 21, 2022

Hi @jedelbo, any insights into this?
Just so that I can communicate an update to my clients as well.

@jedelbo
Copy link
Contributor

jedelbo commented Oct 26, 2022

I have spent quite amount of time trying to figure out why the a realm file could end up like the one I received. Unfortunately it did not point in a specific direction. Can I ask you if you continue to get issues from new users?

@michalrentka
Copy link
Author

@jedelbo unfortunately I don't have other crash reports now. From time to time similar crash report from Realm pops up from our users, but not quite the same. I'll update this ticket when I have database and report from more users.

In my case, the database is shared with share extension via app group shared folder. The share extension can be used quite often and it also includes background upload which writes to database when the upload finishes. So maybe it could be some combination of access from main app, share extension and main app in background?

Otherwise I can't think of anything unusual in the app. All reads are performed on main queue. All writes are performed on background queues. There can be multiple queues writing. Background writes are performed in autorelease pools.

If you have any guesses what could cause this, try to write them down and maybe something will ring a bell.

@sedwo
Copy link

sedwo commented Oct 27, 2022

@jedelbo Is it possible for the app to somehow recover any data from this DB state?

@jedelbo
Copy link
Contributor

jedelbo commented Oct 28, 2022

We now have the hypothesis that some pages are not written to the file system - probably caused by the phone somehow crashing. So, as we are lacking some data, there is no way to recover. Our design is meant to guarantee that data is written in the order expected, but it seem like that is not achieved on iOS. We expect to have a solution soon.

@sedwo
Copy link

sedwo commented Nov 4, 2022

Hi @jedelbo, any update to this?

@jedelbo
Copy link
Contributor

jedelbo commented Nov 9, 2022

We will probably make a release later today with a possible fix. You can follow the progress here: #5993.

@NZQN23
Copy link

NZQN23 commented Nov 9, 2022

Will this only prevent this particular behavior in the future or will it also fix apps with already corrupted database?

@jedelbo
Copy link
Contributor

jedelbo commented Nov 9, 2022

Unfortunately we cannot automatically fix already corrupted databases.

@NZQN23
Copy link

NZQN23 commented Nov 11, 2022

Hi @jedelbo when will a new Swift version will be released that contains this fix? The changelog for the new release seems not to contain it: https://github.com/realm/realm-swift/releases/tag/v10.32.3

@jedelbo
Copy link
Contributor

jedelbo commented Nov 17, 2022

Closed by #5993

@jedelbo jedelbo closed this as completed Nov 17, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants