-
Type: Bug
-
Resolution: Duplicate
-
Priority: Critical - P2
-
None
-
Affects Version/s: None
-
Component/s: None
Expected results
App shouldn't crash when setting value to existing object.
Actual Results
App crashes when accessing existing object and setting value to it.
Steps & Code to Reproduce
I can't reproduce this issue myself, but I can see multiple reports of this on TestFlight. The app has a background sync of data from our server. This issue happens when I want to update an existing object with a new version number after the sync. I've seen reports from multiple users which point to this issue in the same part of the app (same database write).
All writes in the app run on background serial queues. All reads (accessed by UI) run on main queue. There can be multiple serial queues writing in background at the same time.
The crash happens here: https://github.com/zotero/zotero-ios/blob/5c27b78a64eba144e67113cd10d1687ff97b920a/Zotero/Controllers/Sync/SyncActions/StoreVersionSyncAction.swift#L27
UpdateVersionsDbRequest can be found here: https://github.com/zotero/zotero-ios/blob/5c27b78a64eba144e67113cd10d1687ff97b920a/Zotero/Controllers/Database/Requests/UpdateVersionsDbRequest.swift#L25-L67.
I have a simple wrapper for accessing Realm found here: https://github.com/zotero/zotero-ios/blob/5c27b78a64eba144e67113cd10d1687ff97b920a/Zotero/Controllers/Database/RealmDbStorage.swift#L92-L99
https://github.com/zotero/zotero-ios/blob/5c27b78a64eba144e67113cd10d1687ff97b920a/Zotero/Controllers/Database/RealmDbStorage.swift#L121-L136
RCustomLibrary and RGroup are simple realm objects, both with RVersions: EmbeddedObject:
https://github.com/zotero/zotero-ios/blob/master/Zotero/Models/Database/RCustomLibrary.swift
https://github.com/zotero/zotero-ios/blob/master/Zotero/Models/Database/RGroup.swift
https://github.com/zotero/zotero-ios/blob/master/Zotero/Models/Database/RVersions.swift
To sum it up: the sync process happens in background serial queue. When it's finished for given object type (item, collection, search, ...) it wants to write new version value to RVersions object stored either in RCustomLibrary or RGroup, where RVersions is an EmbeddedObject. New Realm is opened (in the same background serial queue), new write transaction is started in autoreleasepool, a RCustomLibrary or RGroup object is fetched from database and there is an attempt to write to RVersions object when the app crashes.
Incident Identifier: 8B274DC3-3A2F-4D1D-9C08-7008ACBF41B7 Hardware Model: iPad13,10 Process: Zotero [1611] Path: /private/var/containers/Bundle/Application/E3514FDA-B0A9-424F-98E3-9F150245D2EE/Zotero.app/Zotero Identifier: org.zotero.ios.Zotero Version: 1.0.4 (8) AppStoreTools: 13F100 AppVariant: 1:iPad13,10:15 Beta: YES Code Type: ARM-64 (Native) Role: Foreground Parent Process: launchd [1] Coalition: org.zotero.ios.Zotero [781] Date/Time: 2022-08-17 18:54:49.5780 -0700 Launch Time: 2022-08-17 18:54:46.8581 -0700 OS Version: iPhone OS 15.6.1 (19G82) Release Type: User Baseband Version: 2.70.01 Report Version: 104 Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Note: EXC_CORPSE_NOTIFY Triggered by Thread: 4 Thread 0 name: Thread 0: 0 libsystem_kernel.dylib 0x00000001b73674a0 0x1b7366000 + 5280 1 libsystem_kernel.dylib 0x00000001b7367ae4 0x1b7366000 + 6884 2 CoreFoundation 0x000000018039fd30 __CFRunLoopServiceMachPort + 372 (CFRunLoop.c:2646) 3 CoreFoundation 0x00000001803a41bc __CFRunLoopRun + 1180 (CFRunLoop.c:3000) 4 CoreFoundation 0x00000001803b7bc8 CFRunLoopRunSpecific + 600 (CFRunLoop.c:3268) 5 GraphicsServices 0x000000019c523374 GSEventRunModal + 164 (GSEvent.c:2200) 6 UIKitCore 0x0000000182d2bb58 -[UIApplication _run] + 1100 (UIApplication.m:3511) 7 UIKitCore 0x0000000182aad090 UIApplicationMain + 364 (UIApplication.m:5064) 8 Zotero 0x0000000100163890 main + 204 (main.swift:13) 9 dyld 0x0000000101505da4 start + 520 (dyldMain.cpp:879) Thread 1: 0 libsystem_pthread.dylib 0x00000001f0b24e54 0x1f0b24000 + 3668 Thread 2: 0 libsystem_pthread.dylib 0x00000001f0b24e54 0x1f0b24000 + 3668 Thread 3 name: Thread 3: 0 libsystem_kernel.dylib 0x00000001b73699cc 0x1b7366000 + 14796 1 libsystem_kernel.dylib 0x00000001b73690bc 0x1b7366000 + 12476 2 libsqlite3.dylib 0x000000019f3a92f4 unixShmSystemLock + 196 (sqlite3.c:37379) 3 libsqlite3.dylib 0x000000019f317008 unixShmLock + 276 (sqlite3.c:43252) 4 libsqlite3.dylib 0x000000019f3130c8 sqlite3PagerSharedLock + 104 (sqlite3.c:24883) 5 libsqlite3.dylib 0x000000019f312b60 sqlite3BtreeBeginTrans + 1472 (sqlite3.c:75474) 6 libsqlite3.dylib 0x000000019f332dc4 sqlite3VdbeExec + 3000 (sqlite3.c:97710) 7 libsqlite3.dylib 0x000000019f331248 sqlite3_step + 312 (sqlite3.c:92283) 8 libsqlite3.dylib 0x000000019f2f6d04 sqlite3_exec + 356 (sqlite3.c:134587) 9 CFNetwork 0x0000000180c054f0 -[NSURLStorageURLCacheDB execSQLStatement:onConnection:toCompletionWithRetry:writeLockHeld:] + 104 (NSURLStorageURLCacheDB.mm:2011) 10 CFNetwork 0x0000000180c99404 ___ZN12__CFURLCache23CreateAndStoreCacheNodeEP16__CFURLCacheNodePK20_CFCachedURLResponsePK10__CFStringPK13_CFURLRequestPKvbRb_block_invoke + 260 (NSURLStorageURLCacheDB.mm:2084) 11 libdispatch.dylib 0x00000001800a8830 _dispatch_block_async_invoke2 + 148 (queue.c:560) 12 libdispatch.dylib 0x0000000180099a30 _dispatch_client_callout + 20 (object.m:560) 13 libdispatch.dylib 0x00000001800a1124 _dispatch_lane_serial_drain + 668 (inline_internal.h:2622) 14 libdispatch.dylib 0x00000001800a1cb4 _dispatch_lane_invoke + 444 (queue.c:3944) 15 libdispatch.dylib 0x00000001800ac500 _dispatch_workloop_worker_thread + 648 (queue.c:6732) 16 libsystem_pthread.dylib 0x00000001f0b250bc 0x1f0b24000 + 4284 17 libsystem_pthread.dylib 0x00000001f0b24e5c 0x1f0b24000 + 3676 Thread 4 name: Thread 4 Crashed: 0 libsystem_kernel.dylib 0x00000001b736db38 0x1b7366000 + 31544 1 libsystem_pthread.dylib 0x00000001f0b2b3bc 0x1f0b24000 + 29628 2 libsystem_c.dylib 0x000000018b544524 abort + 168 (abort.c:118) 3 Zotero 0x0000000100bf9edc please_report_this_issue_in_github_realm_realm_core + 12 (terminate.cpp:50) 4 Zotero 0x0000000100bfa21c realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 244 (terminate.cpp:123) 5 Zotero 0x0000000100bf9f98 realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) + 188 (terminate.cpp:133) 6 Zotero 0x0000000100812a64 void realm::util::terminate<realm::NodeHeader::WidthType, realm::NodeHeader::WidthType>(char const*, char const*, long, realm::NodeHeader::WidthType, realm::NodeHeader::WidthType) + 60 (terminate.hpp:45) 7 Zotero 0x0000000100a08b58 realm::Node::calc_byte_len(unsigned long, unsigned long) const + 76 (node.cpp:45) 8 Zotero 0x0000000100a08ddc realm::Node::do_copy_on_write(unsigned long) + 68 (node.cpp:131) 9 Zotero 0x0000000100986e50 realm::Node::copy_on_write() + 28 (node.hpp:299) 10 Zotero 0x0000000100986e50 realm::Array::set(unsigned long, long long) + 124 (array.cpp:378) 11 Zotero 0x0000000100a102bc realm::Obj& realm::Obj::set<long long>(realm::ColKey, long long, bool) + 436 (obj.cpp:1346) 12 Zotero 0x00000001007924cc void (anonymous namespace)::setValue<long long>(RLMObjectBase*, realm::ColKey, long long) + 28 (RLMAccessor.mm:120) 13 Zotero 0x00000001007924cc void (anonymous namespace)::kvoSetValue<long long, long long>(RLMObjectBase*, unsigned long, long long) + 112 (RLMAccessor.mm:404) 14 Zotero 0x00000001009426a4 Persisted.set(_:value:) + 1104 (PersistedProperty.swift:207) 15 Zotero 0x00000001009440e0 specialized static Persisted.subscript.setter + 108 (PersistedProperty.swift:129) 16 Zotero 0x0000000100942b4c static Persisted.subscript.setter + 48 (<compiler-generated>:0) 17 Zotero 0x000000010046f204 specialized UpdateVersionsDbRequest.update(versions:type:version:) + 264 (UpdateVersionsDbRequest.swift:0) 18 Zotero 0x000000010046f060 UpdateVersionsDbRequest.process(in:) + 260 (UpdateVersionsDbRequest.swift:0) 19 Zotero 0x000000010046f0e8 protocol witness for DbRequest.process(in:) in conformance UpdateVersionsDbRequest + 32 (<compiler-generated>:0) 20 Zotero 0x000000010038a844 $s6Zotero18RealmDbCoordinatorV7perform7requestyAA0C7Request_p_tKFyyKXEfU_ + 44 (RealmDbStorage.swift:134) 21 Zotero 0x000000010038a844 partial apply for closure #1 in RealmDbCoordinator.perform(request:) + 68 (<compiler-generated>:0) 22 Zotero 0x000000010094fe40 Realm.write<A>(withoutNotifying:_:) + 180 (Realm.swift:258) 23 Zotero 0x0000000100389460 RealmDbCoordinator.perform(request:) + 876 (RealmDbStorage.swift:133) 24 Zotero 0x0000000100388ecc closure #1 in RealmDbStorage.perform(request:on:) + 400 (RealmDbStorage.swift:95) 25 Zotero 0x000000010038a7d8 partial apply for closure #1 in RealmDbStorage.perform(request:on:) + 20 (<compiler-generated>:0) 26 Zotero 0x000000010038a7f4 $s6Zotero14RealmDbStorageC32performInAutoreleasepoolIfNeeded33_0C0F801E5634ADE4DF1A4E8CD0CAA38DLL8invokingxxyKXE_tKlFxyKXEfU_yt_Tg5 + 4 (RealmDbStorage.swift:51) 27 Zotero 0x000000010038a7f4 partial apply for specialized closure #1 in RealmDbStorage.performInAutoreleasepoolIfNeeded<A>(invoking:) + 20 (<compiler-generated>:0) 28 libswiftObjectiveC.dylib 0x00000001ae43aa10 autoreleasepool<A>(invoking:) + 64 (ObjectiveC.swift:172) 29 Zotero 0x0000000100388b94 $s6Zotero14RealmDbStorageC32performInAutoreleasepoolIfNeeded33_0C0F801E5634ADE4DF1A4E8CD0CAA38DLL8invokingxxyKXE_tKlFyt_Tg5 + 320 (RealmDbStorage.swift:50) 30 Zotero 0x0000000100388b94 RealmDbStorage.perform(request:on:) + 668 (RealmDbStorage.swift:93) 31 Zotero 0x00000001004f7f48 $s6Zotero14RealmDbStorageCAA0cD0A2aDP7perform7request2onyAA0C7Request_p_So17OS_dispatch_queueCtKFTW + 12 (<compiler-generated>:0) 32 Zotero 0x00000001004f7f48 closure #1 in StoreVersionSyncAction.result.getter + 124 (StoreVersionSyncAction.swift:27) 33 Zotero 0x000000010061b718 $s7RxSwift21PrimitiveSequenceTypePA2A11SingleTraitO0G0RtzrlE6create9subscribeAA0cD0VyAE7ElementQzGAA10Disposable_pys6ResultOyAMs5Error_pGcc_tFZAaO_pAA11AnyObserverVyAMGcfU_ + 60 (Single.swift:32) 34 Zotero 0x000000010061b718 partial apply for closure #1 in static PrimitiveSequenceType<>.create(subscribe:) + 104 (<compiler-generated>:0) 35 Zotero 0x00000001005d3dac $s7RxSwift23AnonymousObservableSink33_95EBF5692819D58425EC2DD0512D115ALLC3runyAA10Disposable_pAA0cD0ACLLCy7ElementQzGF + 60 (Create.swift:60) 36 Zotero 0x00000001005d3dac AnonymousObservable.run<A>(_:cancel:) + 240 (Create.swift:75) 37 Zotero 0x0000000100605728 closure #1 in Producer.subscribe<A>(_:) + 228 (Producer.swift:26) 38 Zotero 0x0000000100604e14 specialized CurrentThreadScheduler.schedule<A>(_:action:) + 168 (CurrentThreadScheduler.swift:94) 39 Zotero 0x0000000100604d14 Producer.subscribe<A>(_:) + 496 (Producer.swift:24) 40 Zotero 0x00000001005fa600 protocol witness for ObservableType.subscribe<A>(_:) in conformance Observable<A> + 28 (<compiler-generated>:0) 41 Zotero 0x000000010061fcec closure #1 in SubscribeOnSink.run() + 152 (SubscribeOn.swift:78) 42 Zotero 0x00000001005de190 $s7RxSwift26DispatchQueueConfigurationV8schedule_6actionAA10Disposable_px_AaF_pxctlFyycfU_ + 8 (DispatchQueueConfiguration.swift:27) 43 Zotero 0x00000001005de190 partial apply for closure #1 in DispatchQueueConfiguration.schedule<A>(_:action:) + 120 (<compiler-generated>:0) 44 Zotero 0x00000001005d3594 thunk for @escaping @callee_guaranteed () -> () + 28 (<compiler-generated>:0) 45 libdispatch.dylib 0x0000000180097e6c _dispatch_call_block_and_release + 32 (init.c:1517) 46 libdispatch.dylib 0x0000000180099a30 _dispatch_client_callout + 20 (object.m:560) 47 libdispatch.dylib 0x00000001800a1124 _dispatch_lane_serial_drain + 668 (inline_internal.h:2622) 48 libdispatch.dylib 0x00000001800a1cb4 _dispatch_lane_invoke + 444 (queue.c:3944) 49 libdispatch.dylib 0x00000001800a1000 _dispatch_lane_serial_drain + 376 (inline_internal.h:0) 50 libdispatch.dylib 0x00000001800a1c80 _dispatch_lane_invoke + 392 (queue.c:3944) 51 libdispatch.dylib 0x00000001800ac500 _dispatch_workloop_worker_thread + 648 (queue.c:6732) 52 libsystem_pthread.dylib 0x00000001f0b250bc 0x1f0b24000 + 4284 53 libsystem_pthread.dylib 0x00000001f0b24e5c 0x1f0b24000 + 3676 Thread 5: 0 libsystem_pthread.dylib 0x00000001f0b24e54 0x1f0b24000 + 3668 Thread 6 name: Thread 6: 0 libsystem_kernel.dylib 0x00000001b73674a0 0x1b7366000 + 5280 1 libsystem_kernel.dylib 0x00000001b7367ae4 0x1b7366000 + 6884 2 CoreFoundation 0x000000018039fd30 __CFRunLoopServiceMachPort + 372 (CFRunLoop.c:2646) 3 CoreFoundation 0x00000001803a41bc __CFRunLoopRun + 1180 (CFRunLoop.c:3000) 4 CoreFoundation 0x00000001803b7bc8 CFRunLoopRunSpecific + 600 (CFRunLoop.c:3268) 5 Foundation 0x0000000181baa444 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 236 (NSRunLoop.m:373) 6 Foundation 0x0000000181bebe0c -[NSRunLoop(NSRunLoop) runUntilDate:] + 92 (NSRunLoop.m:420) 7 UIKitCore 0x0000000182ca5cc4 -[UIEventFetcher threadMain] + 524 (UIEventFetcher.m:1167) 8 Foundation 0x0000000181bfa41c __NSThread__start__ + 808 (NSThread.m:972) 9 libsystem_pthread.dylib 0x00000001f0b259ac 0x1f0b24000 + 6572 10 libsystem_pthread.dylib 0x00000001f0b24e68 0x1f0b24000 + 3688 Thread 7: 0 libsystem_pthread.dylib 0x00000001f0b24e54 0x1f0b24000 + 3668 Thread 8: 0 libsystem_kernel.dylib 0x00000001b73674a0 0x1b7366000 + 5280 1 libsystem_kernel.dylib 0x00000001b7367ae4 0x1b7366000 + 6884 2 Zotero 0x0000000100c2cffc exception_server_thread + 188 (PLCrashMachExceptionServer.m:674) 3 libsystem_pthread.dylib 0x00000001f0b259ac 0x1f0b24000 + 6572 4 libsystem_pthread.dylib 0x00000001f0b24e68 0x1f0b24000 + 3688 Thread 9 name: Thread 9: 0 libsystem_kernel.dylib 0x00000001b7368e18 0x1b7366000 + 11800 1 Zotero 0x0000000100a345bc realm::_impl::ExternalCommitHelper::listen() + 160 (external_commit_helper.cpp:220) 2 Zotero 0x0000000100a349b0 realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0::operator()() const + 4 (external_commit_helper.cpp:176) 3 Zotero 0x0000000100a349b0 decltype(static_cast<realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm::_impl::RealmCoordinator&)::$_0>(fp)()) std::__1::__invoke<realm::_impl::ExternalCommitHelper::ExternalCommitHelp... + 4 (type_traits:3918) 4 Zotero 0x0000000100a349b0 void std::__1::__thread_execute<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, realm::_impl::ExternalCommitHelper::ExternalCommitHelper(realm... + 4 (thread:287) 5 Zotero 0x0000000100a349b0 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, realm::_impl::ExternalCommitHelper::ExternalCom... + 52 (thread:298) 6 libsystem_pthread.dylib 0x00000001f0b259ac 0x1f0b24000 + 6572 7 libsystem_pthread.dylib 0x00000001f0b24e68 0x1f0b24000 + 3688 Thread 10: 0 libsystem_pthread.dylib 0x00000001f0b24e54 0x1f0b24000 + 3668 Thread 11 name: Thread 11: 0 libsystem_kernel.dylib 0x00000001b73674a0 0x1b7366000 + 5280 1 libsystem_kernel.dylib 0x00000001b7367ae4 0x1b7366000 + 6884 2 CoreFoundation 0x000000018039fd30 __CFRunLoopServiceMachPort + 372 (CFRunLoop.c:2646) 3 CoreFoundation 0x00000001803a41bc __CFRunLoopRun + 1180 (CFRunLoop.c:3000) 4 CoreFoundation 0x00000001803b7bc8 CFRunLoopRunSpecific + 600 (CFRunLoop.c:3268) 5 CFNetwork 0x0000000180e341dc +[__CFN_CoreSchedulingSetRunnable _run:] + 472 (CoreSchedulingSet.mm:1372) 6 Foundation 0x0000000181bfa41c __NSThread__start__ + 808 (NSThread.m:972) 7 libsystem_pthread.dylib 0x00000001f0b259ac 0x1f0b24000 + 6572 8 libsystem_pthread.dylib 0x00000001f0b24e68 0x1f0b24000 + 3688 Thread 4 crashed with ARM Thread State (64-bit): x0: 0x0000000000000000 x1: 0x0000000000000000 x2: 0x0000000000000000 x3: 0x0000000000000000 x4: 0x0000000000000012 x5: 0x000000014003fc00 x6: 0x0000000000001800 x7: 0x0000000000000000 x8: 0x162ee1dd066a2d4d x9: 0x162ee1dc6986dd4d x10: 0x00000000007bca00 x11: 0x0000000000bf3d01 x12: 0x0000000000004009 x13: 0x0000000140040000 x14: 0x0000000000003fff x15: 0x000000000000dc19 x16: 0x0000000000000148 x17: 0x000000016fecf000 x18: 0x0000000000000000 x19: 0x0000000000000006 x20: 0x0000000000002203 x21: 0x000000016fecf0e0 x22: 0x000000016fecd210 x23: 0x0000000100cca106 x24: 0x0000000107a058b0 x25: 0x000000000027d8b0 x26: 0x0000000282bc3b80 x27: 0x0000000000000004 x28: 0x000000016fecd838 fp: 0x000000016fecd150 lr: 0x00000001f0b2b3bc sp: 0x000000016fecd130 pc: 0x00000001b736db38 cpsr: 0x40001000 esr: 0x56000080 Address size fault Binary Images: 0x10015c000 - 0x100e9ffff Zotero arm64 <ae979ea4c9fd3e98bbded9094e52600f> /private/var/containers/Bundle/Application/E3514FDA-B0A9-424F-98E3-9F150245D2EE/Zotero.app/Zotero 0x1014ec000 - 0x101543fff dyld arm64e <66e1fb2668f8379ba052eb8b8291b5e1> /usr/lib/dyld 0x180096000 - 0x1800dbfff libdispatch.dylib arm64e <e3ea4f635d11342aaf199f58dbc8e259> /usr/lib/system/libdispatch.dylib 0x180399000 - 0x1807eefff CoreFoundation arm64e <6b22dd8135853be6bc77ba19810ec0f2> /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 0x180bbc000 - 0x18107dfff CFNetwork arm64e <106410ffdd4f3527ad531980fe8b0ddd> /System/Library/Frameworks/CFNetwork.framework/CFNetwork 0x181b91000 - 0x181e9bfff Foundation arm64e <ee1abaf23d7137fb906715aa79528619> /System/Library/Frameworks/Foundation.framework/Foundation 0x182817000 - 0x1840b4fff UIKitCore arm64e <137a95aada6d332cbc01e13bb9b6e317> /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore 0x18b524000 - 0x18b5a3fff libsystem_c.dylib arm64e <86a1a24ace353769ba6960f28353281e> /usr/lib/system/libsystem_c.dylib 0x19c522000 - 0x19c52afff GraphicsServices arm64e <a094e7b51d4037c5902756d86988ec4b> /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices 0x19f2ed000 - 0x19f485fff libsqlite3.dylib arm64e <f9afcada4db33c15985eedb2dac7b25c> /usr/lib/libsqlite3.dylib 0x1ae439000 - 0x1ae43bfff libswiftObjectiveC.dylib arm64e <7eb9c85783d83c8bbf9bf55779a9ac76> /usr/lib/swift/libswiftObjectiveC.dylib 0x1b7366000 - 0x1b739bfff libsystem_kernel.dylib arm64e <1fb39303587b320eaeb8e51a54c8a4a9> /usr/lib/system/libsystem_kernel.dylib 0x1f0b24000 - 0x1f0b2ffff libsystem_pthread.dylib arm64e <adc41700002e3a2bb4a1eb5fbf575770> /usr/lib/system/libsystem_pthread.dylib
Core version
Core version: 12.5.0 (Realm version 10.28.5)