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

Startup crash #5344

Closed
michalrentka opened this issue Mar 21, 2022 · 6 comments
Closed

Startup crash #5344

michalrentka opened this issue Mar 21, 2022 · 6 comments
Assignees

Comments

@michalrentka
Copy link

SDK and version

SDK : Cocoa
Version: 10.23.0

Observations

A user reported crashing on each startup. It was an existing user who probably recently updated the app, so it could be a migration issue. I can't reproduce it myself. The stack trace said to share the crash log.

Crash log / stacktrace

Incident Identifier: 847FA702-AAB7-47FF-B994-D6C44190E223
Hardware Model:      iPad11,6
Process:             Zotero [455]
Path:                /private/var/containers/Bundle/Application/CBA1C89E-D822-4165-8554-FA2A821654D5/Zotero.app/Zotero
Identifier:          org.zotero.ios.Zotero
Version:             1.0 (199)
AppStoreTools:       13E112
AppVariant:          1:iPad11,6:15
Beta:                YES
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           org.zotero.ios.Zotero [532]

Date/Time:           2022-03-18 14:45:32.8394 -0500
Launch Time:         2022-03-18 14:45:32.7117 -0500
OS Version:          iPhone OS 15.4 (19E241)
Release Type:        User
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0


Kernel Triage:
VM - pmap_enter failed with resource shortage
VM - pmap_enter failed with resource shortage
VM - pmap_enter failed with resource shortage
VM - pmap_enter failed with resource shortage
VM - pmap_enter failed with resource shortage


Thread 0 name:
Thread 0 Crashed:
0   libsystem_kernel.dylib        	0x00000001b71e7b78 __pthread_kill + 8
1   libsystem_pthread.dylib       	0x00000001f02783bc pthread_kill + 268 (pthread.c:1668)
2   libsystem_c.dylib             	0x000000018b57d51c abort + 168 (abort.c:118)
3   Zotero                        	0x0000000100dc4968 please_report_this_issue_in_github_realm_realm_core + 12 (terminate.cpp:50)
4   Zotero                        	0x0000000100dc4b6c realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 244 (terminate.cpp:123)
5   Zotero                        	0x0000000100dc4ca4 realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) + 188 (terminate.cpp:140)
6   Zotero                        	0x00000001009447cc void realm::util::terminate<unsigned long long, long>(char const*, char const*, long, unsigned long long, long) + 52 (terminate.hpp:45)
7   Zotero                        	0x0000000100b23680 realm::Allocator::translate_critical(realm::Allocator::RefTranslation*, unsigned long) const + 36 (alloc.hpp:590)
8   Zotero                        	0x0000000100b23680 realm::Allocator::translate(unsigned long) const + 56 (alloc.hpp:598)
9   Zotero                        	0x0000000100b23680 realm::Array::init_from_ref(unsigned long) + 220 (array.hpp:118)
10  Zotero                        	0x0000000100d839b0 realm::Table::init(unsigned long, realm::ArrayParent*, unsigned long, bool, bool) + 64 (table.cpp:568)
11  Zotero                        	0x0000000100b6ca3c realm::Group::create_table_accessor(unsigned long) + 800 (group.cpp:991)
12  Zotero                        	0x0000000100b6c6c4 realm::Group::do_get_table(unsigned long) + 96 (group.cpp:865)
13  Zotero                        	0x0000000100c26680 realm::Group::do_get_table(realm::StringData) const + 16 (group.hpp:1221)
14  Zotero                        	0x0000000100c26680 realm::Group::get_table(realm::StringData) const + 24 (group.hpp:1038)
15  Zotero                        	0x0000000100c26680 realm::ObjectStore::get_schema_version(realm::Group const&) + 40 (object_store.cpp:229)
16  Zotero                        	0x0000000100c688ac realm::Realm::read_schema_from_group_if_needed() + 140 (shared_realm.cpp:231)
17  Zotero                        	0x0000000100c686cc realm::Realm::Realm(realm::Realm::Config, realm::util::Optional<realm::VersionID>, std::__1::shared_ptr<realm::_impl::RealmCoordinator>, realm::Realm::MakeSharedTag) + 400 (shared_realm.cpp:85)
18  Zotero                        	0x0000000100c05b50 std::__1::__shared_ptr_emplace<realm::Realm, std::__1::allocator<realm::Realm> >::__shared_ptr_emplace<realm::Realm::Config, realm::util::Optional<realm::VersionID>, std::__1::shared_ptr<realm::_im... + 104 (memory:2627)
19  Zotero                        	0x0000000100c05b50 std::__1::__shared_ptr_emplace<realm::Realm, std::__1::allocator<realm::Realm> >::__shared_ptr_emplace<realm::Realm::Config, realm::util::Optional<realm::VersionID>, std::__1::shared_ptr<realm::_im... + 104 (memory:2621)
20  Zotero                        	0x0000000100c05b50 std::__1::shared_ptr<realm::Realm> std::__1::allocate_shared<realm::Realm, std::__1::allocator<realm::Realm>, realm::Realm::Config, realm::util::Optional<realm::VersionID>, std::__1::shared_ptr<rea... + 116 (memory:3385)
21  Zotero                        	0x0000000100c05b50 std::__1::shared_ptr<realm::Realm> std::__1::make_shared<realm::Realm, realm::Realm::Config, realm::util::Optional<realm::VersionID>, std::__1::shared_ptr<realm::_impl::RealmCoordinator>, realm::Re... + 116 (memory:3394)
22  Zotero                        	0x0000000100c05b50 realm::Realm::make_shared_realm(realm::Realm::Config, realm::util::Optional<realm::VersionID>, std::__1::shared_ptr<realm::_impl::RealmCoordinator>) + 176 (shared_realm.hpp:414)
23  Zotero                        	0x0000000100c051ec realm::_impl::RealmCoordinator::do_get_realm(realm::Realm::Config, std::__1::shared_ptr<realm::Realm>&, realm::util::Optional<realm::VersionID>, realm::util::CheckedUniqueLock&) + 260 (realm_coordinator.cpp:360)
24  Zotero                        	0x0000000100c04f9c realm::_impl::RealmCoordinator::get_realm(realm::Realm::Config, realm::util::Optional<realm::VersionID>) + 480 (realm_coordinator.cpp:324)
25  Zotero                        	0x0000000100c6c3d0 realm::Realm::get_schema_version(realm::Realm::Config const&) + 136 (shared_realm.cpp:1179)
26  Zotero                        	0x0000000100a55548 +[RLMRealm schemaVersionAtURL:encryptionKey:error:] + 188 (RLMRealm.mm:934)
27  Zotero                        	0x0000000100ac67dc schemaVersionAtURL(_:encryptionKey:) + 120 (Migration.swift:55)
28  Zotero                        	0x00000001004d6e00 static Database.shouldDeleteRealm(url:) + 20 (Database.swift:36)
29  Zotero                        	0x00000001004d6e00 static Database.mainConfiguration(url:fileStorage:) + 208 (Database.swift:19)
30  Zotero                        	0x0000000100515554 specialized static UserControllers.createDbStorage(for:controllers:) + 400 (Controllers.swift:383)
31  Zotero                        	0x000000010051613c static UserControllers.createDbStorage(for:controllers:) + 16 (<compiler-generated>:0)
32  Zotero                        	0x000000010051613c specialized UserControllers.init(userId:controllers:) + 148
33  Zotero                        	0x000000010051613c 0x100364000 + 1777980 (Controllers.swift:279)
34  Zotero                        	0x00000001005135a8 UserControllers.init(userId:controllers:) + 16 (Controllers.swift:0)
35  Zotero                        	0x00000001005135a8 UserControllers.__allocating_init(userId:controllers:) + 16 (Controllers.swift:193)
36  Zotero                        	0x00000001005135a8 Controllers.set(sessionData:isLogin:debugLogging:) + 304
37  Zotero                        	0x00000001005121b8 Controllers.update(with:isLogin:debugLogging:) + 24 (Controllers.swift:176)
38  Zotero                        	0x00000001005121b8 Controllers.initializeSessionIfPossible(failOnError:) + 868 (Controllers.swift:120)
39  Zotero                        	0x0000000100511d90 Controllers.init() + 2640 (Controllers.swift:90)
40  Zotero                        	0x000000010067cf74 Controllers.__allocating_init() + 28 (Controllers.swift:0)
41  Zotero                        	0x000000010067cf74 specialized AppDelegate.application(_:didFinishLaunchingWithOptions:) + 592 (AppDelegate.swift:266)
42  Zotero                        	0x000000010067be54 AppDelegate.application(_:didFinishLaunchingWithOptions:) + 4 (<compiler-generated>:0)
43  Zotero                        	0x000000010067be54 @objc AppDelegate.application(_:didFinishLaunchingWithOptions:) + 132
44  UIKitCore                     	0x0000000182b96f88 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 340 (UIApplication.m:2334)
45  UIKitCore                     	0x0000000182d7dda4 -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 3572 (UIApplication.m:2754)
46  UIKitCore                     	0x0000000182d66958 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1180 (UIApplication.m:4491)
47  UIKitCore                     	0x0000000182bc45d0 -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 216 (_UISceneLifecycleMultiplexer.m:450)
48  UIKitCore                     	0x0000000182bc39dc -[UIApplication _compellApplicationLaunchToCompleteUnconditionally] + 68 (UIApplication.m:3397)
49  UIKitCore                     	0x0000000182d85e64 -[UIApplication _run] + 1064 (UIApplication.m:0)
50  UIKitCore                     	0x0000000182b075ec UIApplicationMain + 364 (UIApplication.m:5064)
51  Zotero                        	0x00000001003694b8 main + 204 (main.swift:13)
52  dyld                          	0x0000000101699ce4 start + 520 (dyldMain.cpp:879)

Steps & Code to Reproduce

From the crash report it looks like it's crashing when trying to read a schema version:
https://github.com/zotero/zotero-ios/blob/ea44d2c74a7b115d3f88d61c781f3daccfd7aa1e/Zotero/Models/Database/Database.swift#L36.
It's not really needed at this point, so if I shouldn't read schema version before Realm is initialised, I'll get rid of it.

@danieltabacaru
Copy link
Collaborator

@michalrentka Thank you for filling this issue. We are looking into it.

@danieltabacaru
Copy link
Collaborator

@ironage There seems to be a problem when reading the schema version from the metadata table (although open_db succeeds). Could you please have a look at this?

@ironage
Copy link
Contributor

ironage commented Mar 22, 2022

It is a shame we don't have the std::cerr output from this report. I assume from the stack trace that the cookie check fails. I wonder if there be a race on the allocator's m_ref_translation_ptr? @finnschiermer does this look familiar?
@michalrentka does your application have other threads operating on this Realm as well?

@michalrentka
Copy link
Author

@ironage no, I always open a new realm when I work with database. So each thread should have separate realms.

To explain a bit how I work with Realm, I made this simple wrapper to access the database: https://github.com/zotero/zotero-ios/blob/master/Zotero/Controllers/Database/RealmDbStorage.swift

The app has a single DbStorage instance which holds a realm configuration. When I want to access realm I create a DbCoordinator which holds a Realm instance and on that coordinator I perform requests. I never share coordinator between threads. A simple DbRequest example is here: https://github.com/zotero/zotero-ios/blob/master/Zotero/Controllers/Database/Requests/InitializeCustomLibrariesDbRequest.swift.

Also, this crash happened after app launch (https://github.com/zotero/zotero-ios/blob/6eedfef089276fbe8aa2d16690eeb49885873c0c/Zotero/Controllers/Controllers.swift#L383) when I try to create a shared Realm.Configuration and read the schema version: https://github.com/zotero/zotero-ios/blob/6eedfef089276fbe8aa2d16690eeb49885873c0c/Zotero/Models/Database/Database.swift#L36. The DbStorage is not initialised, so I didn't even access Realm at this point anywhere.

This is a fresh app start where the only access is made to read schema version from main thread from application(_, didFinishLaunchingWithOptions:) -> Bool

@finnschiermer
Copy link
Contributor

@jedelbo Could this be an earlier instance of #5808 ?

@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