-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
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
- Download app from https://github.com/zotero/zotero-ios
- Download realm files from below comment
- Run the app on iPad / iPhone simulator
- Create free Zotero account and log in with it (or contact me, I'll send you test account privately)
- Replace original db files with downloaded realm files
- Start the app - crash on launch