realm-core icon indicating copy to clipboard operation
realm-core copied to clipboard

Crash when using Realm for both iOS and Kotlin Multiplatform projects (new app)

Open AlexIzh opened this issue 3 years ago • 7 comments

SDK and version

iOS SDK: 10.28.4, KMP SDK: 12.1.0

Observations

  • How frequent do the crash occur? Always
  • Does it happen in production or during dev/test? During development
  • Can the crash be reproduced by you? Yes, always
  • Can you provide instructions for how we can reproduce it? Yes

Crash log / stacktrace

#0	0x00000001cd79db38 in __pthread_kill ()
#1	0x0000000206ece3bc in pthread_kill ()
#2	0x00000001a0e67524 in abort ()
#3	0x0000000103774e50 in ::please_report_this_issue_in_github_realm_realm_core() at /Users/alex/Library/Developer/Xcode/DerivedData/Project-evohrlyjldalplfwzjtxawskwehz/SourcePackages/checkouts/realm-core/src/realm/util/terminate.cpp:50
#4	0x0000000103775234 in realm::util::terminate_internal(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) at /Users/alex/Library/Developer/Xcode/DerivedData/Project-evohrlyjldalplfwzjtxawskwehz/SourcePackages/checkouts/realm-core/src/realm/util/terminate.cpp:123
#5	0x0000000103774f44 in realm::util::terminate(char const*, char const*, long, std::initializer_list<realm::util::Printable>&&) at /Users/alex/Library/Developer/Xcode/DerivedData/Project-evohrlyjldalplfwzjtxawskwehz/SourcePackages/checkouts/realm-core/src/realm/util/terminate.cpp:133
#6	0x000000010289de78 in void realm::util::terminate<unsigned long, unsigned long>(char const*, char const*, long, unsigned long, unsigned long) at /Users/alex/Library/Developer/Xcode/DerivedData/Project-evohrlyjldalplfwzjtxawskwehz/SourcePackages/checkouts/realm-core/src/realm/util/terminate.hpp:45
#7	0x0000000102c73b84 in realm::Array::set(unsigned long, long long) at /Users/alex/Library/Developer/Xcode/DerivedData/Project-evohrlyjldalplfwzjtxawskwehz/SourcePackages/checkouts/realm-core/src/realm/array.cpp:373
#8	0x0000000104dacc84 in realm::Obj& realm::Obj::set<long long>(realm::ColKey, long long, bool) ()
#9	0x00000001030295c8 in realm::Obj& realm::Obj::set<long long>(realm::StringData, long long, bool) at /Users/alex/Library/Developer/Xcode/DerivedData/Project-evohrlyjldalplfwzjtxawskwehz/SourcePackages/checkouts/realm-core/src/realm/obj.hpp:239
#10	0x0000000103024f5c in (anonymous namespace)::create_metadata_tables(realm::Group&) at /Users/alex/Library/Developer/Xcode/DerivedData/Project-evohrlyjldalplfwzjtxawskwehz/SourcePackages/checkouts/realm-core/src/realm/object-store/object_store.cpp:55
#11	0x00000001030267ac in realm::ObjectStore::apply_schema_changes(realm::Transaction&, unsigned long long, realm::Schema&, unsigned long long, realm::SchemaMode, std::__1::vector<realm::SchemaChange, std::__1::allocator<realm::SchemaChange> > const&, std::__1::function<void ()>) at /Users/alex/Library/Developer/Xcode/DerivedData/Project-evohrlyjldalplfwzjtxawskwehz/SourcePackages/checkouts/realm-core/src/realm/object-store/object_store.cpp:844
#12	0x0000000103137018 in realm::Realm::update_schema(realm::Schema, unsigned long long, std::__1::function<void (std::__1::shared_ptr<realm::Realm>, std::__1::shared_ptr<realm::Realm>, realm::Schema&)>, std::__1::function<void (std::__1::shared_ptr<realm::Realm>)>, bool) at /Users/alex/Library/Developer/Xcode/DerivedData/Project-evohrlyjldalplfwzjtxawskwehz/SourcePackages/checkouts/realm-core/src/realm/object-store/shared_realm.cpp:461
#13	0x0000000102a621c8 in +[RLMRealm realmWithConfiguration:queue:error:] at /Users/alex/Library/Developer/Xcode/DerivedData/Project-evohrlyjldalplfwzjtxawskwehz/SourcePackages/checkouts/realm-cocoa/Realm/RLMRealm.mm:594
#14	0x0000000102b297a0 in @nonobjc RLMRealm.__allocating_init(configuration:queue:) ()
#15	0x0000000102bddb18 in Realm.init(configuration:queue:) at /Users/alex/Library/Developer/Xcode/DerivedData/Project-evohrlyjldalplfwzjtxawskwehz/SourcePackages/checkouts/realm-cocoa/RealmSwift/Realm.swift:95
#16	0x00000001024817a4 in BaseLocalDataStore.realm.getter at /Users/alex/Projects/ios-Project/Project/DataManager/LocalDatabase/BaseLocalDataStore.swift:29
#17	0x00000001024929f4 in ThirdPartyConnectedServiceLocalDataStore.bindDelegate(outputDelegate:) at /Users/alex/Projects/ios-Project/Project/Modules/ThirdPartyService/DataStore/ThirdPartyConnectedServiceLocalDataStore.swift:68
#18	0x0000000102493138 in protocol witness for ThirdPartyConnectedServiceLocalDataStoreProtocol.bindDelegate(outputDelegate:) in conformance ThirdPartyConnectedServiceLocalDataStore ()
#19	0x00000001022e9b14 in ThirdPartyServiceRepository.init(remoteDataStore:localDataStore:) at /Users/alex/Projects/ios-Project/Project/Modules/ThirdPartyService/DataStore/ThirdPartyServiceRepository.swift:38
#20	0x00000001022e9a1c in ThirdPartyServiceRepository.__allocating_init(remoteDataStore:localDataStore:) ()
#21	0x000000010237ae20 in one-time initialization function for sharedInstance at /Users/alex/Projects/ios-Project/Project/DataManager/User/DataLayer/UserRepository.swift:30
#22	0x000000010f7027c0 in _dispatch_client_callout ()
#23	0x000000010f704364 in _dispatch_once_callout ()
#24	0x000000010237af50 in UserRepository.sharedInstance.unsafeMutableAddressor at /Users/alex/Projects/ios-Project/Project/DataManager/User/DataLayer/UserRepository.swift:26
#25	0x00000001020ad2d8 in one-time initialization function for sharedInstance at /Users/alex/Projects/ios-Project/Project/DataManager/ServiceProviders/UserServices/UserSessionManager.swift:23
#26	0x000000010f7027c0 in _dispatch_client_callout ()
#27	0x000000010f704364 in _dispatch_once_callout ()
#28	0x00000001020ad398 in UserSessionManager.sharedInstance.unsafeMutableAddressor at /Users/alex/Projects/ios-Project/Project/DataManager/ServiceProviders/UserServices/UserSessionManager.swift:23
#29	0x00000001021d1828 in AppDelegate.init() at /Users/alex/Projects/ios-Project/Project/Application/View/AppDelegate.swift:21
#30	0x00000001021d19c4 in @objc AppDelegate.init() ()
#31	0x000000019909a450 in _UIApplicationMainPreparations ()
#32	0x00000001983d7d74 in UIApplicationMain ()
#33	0x00000001021d2530 in main at /Users/alex/Projects/ios-Project/Project/Application/View/AppDelegate.swift:18
#34	0x000000010ec85ce4 in start ()

Log:

/Users/alex/Library/Developer/Xcode/DerivedData/Project-evohrlyjldalplfwzjtxawskwehz/SourcePackages/checkouts/realm-core/src/realm/array.cpp:373: [realm-core-12.4.0] Assertion failed: ndx < m_size [0, 0]
0   Project                            0x00000001037750b8 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 56
1   Project                            0x0000000103774f44 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 244
2   Project                            0x000000010289de78 _ZN5realm4util9terminateIJmmEEEvPKcS3_lDpT_ + 144
3   Project                            0x0000000102c73b84 _ZN5realm5Array3setEmx + 136
4   Project                            0x0000000104dacc84 _ZN5realm3Obj3setIxEERS0_NS_6ColKeyET_b + 760
5   Project                            0x00000001030295c8 _ZN5realm3Obj3setIxEERS0_NS_10StringDataET_b + 116
6   Project                            0x0000000103024f5c _ZN12_GLOBAL__N_122create_metadata_tablesERN5realm5GroupE + 328
7   Project                            0x00000001030267ac _ZN5realm11ObjectStore20apply_schema_changesERNS_11TransactionEyRNS_6SchemaEyNS_10SchemaModeERKNSt3__16vectorINS_12SchemaChangeENS6_9allocatorIS8_EEEENS6_8functionIFvvEEE + 80
8   Project                            0x0000000103137018 _ZN5realm5Realm13update_schemaENS_6SchemaEyNSt3__18functionIFvNS2_10shared_ptrIS0_EES5_RS1_EEENS3_IFvS5_EEEb + 1396
9   Project                            0x0000000102a621c8 +[RLMRealm realmWithConfiguration:queue:error:] + 2660
10  Project                            0x0000000102b297a0 $sSo8RLMRealmC13configuration5queueABSo0A13ConfigurationC_So012OS_dispatch_C0CSgtKcfCTO + 128
11  Project                            0x0000000102bddb18 $s10RealmSwift0A0V13configuration5queueA2C13ConfigurationV_So012OS_dispatch_D0CSgtKcfC + 204
12  Project                            0x00000001024817a4 $s8Project18BaseLocalDataStoreC5realm10RealmSwift0I0VSgvg + 240
13  Project                            0x00000001024929f4 $s8Project40ThirdPartyConnectedServiceLocalDataStoreC12bindDelegate06outputL0yAA0defghiJ14OutputProtocol_p_tF + 252
14  Project                            0x0000000102493138 $s8Project40ThirdPartyConnectedServiceLocalDataStoreCAA0defghiJ8ProtocolA2aDP12bindDelegate06outputM0yAA0defghij6OutputK0_p_tFTW + 28
15  Project                            0x00000001022e9b14 $s8Project27ThirdPartyServiceRepositoryC15remoteDataStore05localiJ0AcA0def6RemoteiJ8Protocol_p_AA0de9Connectedf5LocalijM0_ptcfc + 232
16  Project                            0x00000001022e9a1c $s8Project27ThirdPartyServiceRepositoryC15remoteDataStore05localiJ0AcA0def6RemoteiJ8Protocol_p_AA0de9Connectedf5LocalijM0_ptcfC + 64
17  Project                            0x000000010237ae20 $s8Project14UserRepositoryC14sharedInstance_WZ + 448
18  libdispatch.dylib                   0x000000010f7027c0 _dispatch_client_callout + 20
19  libdispatch.dylib                   0x000000010f704364 _dispatch_once_callout + 136
20  Project                            0x000000010237af50 $s8Project14UserRepositoryC14sharedInstanceAA0dE8Protocol_pvau + 76
21  Project                            0x00000001020ad2d8 $s8Project18UserSessionManagerC14sharedInstance_WZ + 44
22  libdispatch.dylib                   0x000000010f7027c0 _dispatch_client_callout + 20
23  libdispatch.dylib                   0x000000010f704364 _dispatch_once_callout + 136
24  Project                            0x00000001020ad398 $s8Project18UserSessionManagerC14sharedInstanceACvau + 76
25  Project                            0x00000001021d1828 $s8Project11AppDelegateCACycfc + 172
26  Project                            0x00000001021d19c4 $s8Project11AppDelegateCACycfcTo + 20
27  UIKitCore                           0x000000019909a450 3ED35565-456D-33CB-B554-6C567FA81585 + 16090192
28  UIKitCore                           0x00000001983d7d74 UIApplicationMain + 336
29  Project                            0x00000001021d2530 main + 64
30  dyld                                0x000000010ec85ce4 start + 520!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose2022-08-08 13:27:31.803421+0400 Project[8707:597344] /Users/alex/Library/Developer/Xcode/DerivedData/Project-evohrlyjldalplfwzjtxawskwehz/SourcePackages/checkouts/realm-core/src/realm/array.cpp:373: [realm-core-12.4.0] Assertion failed: ndx < m_size [0, 0]
0   Project                            0x00000001037750b8 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 56
1   Project                            0x0000000103774f44 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 244
2   Project                            0x000000010289de78 _ZN5realm4util9terminateIJmmEEEvPKcS3_lDpT_ + 144
3   Project                            0x0000000102c73b84 _ZN5realm5Array3setEmx + 136
4   Project                            0x0000000104dacc84 _ZN5realm3Obj3setIxEERS0_NS_6ColKeyET_b + 760
5   Project                            0x00000001030295c8 _ZN5realm3Obj3setIxEERS0_NS_10StringDataET_b + 116
6   Project                            0x0000000103024f5c _ZN12_GLOBAL__N_122create_metadata_tablesERN5realm5GroupE + 328
7   Project                            0x00000001030267ac _ZN5realm11ObjectStore20apply_schema_changesERNS_11TransactionEyRNS_6SchemaEyNS_10SchemaModeERKNSt3__16vectorINS_12SchemaChangeENS6_9allocatorIS8_EEEENS6_8functionIFvvEEE + 80
8   Project                            0x0000000103137018 _ZN5realm5Realm13update_schemaENS_6SchemaEyNSt3__18functionIFvNS2_10shared_ptrIS0_EES5_RS1_EEENS3_IFvS5_EEEb + 1396
9   Project                            0x0000000102a621c8 +[RLMRealm realmWithConfiguration:queue:error:] + 2660
10  Project                            0x0000000102b297a0 $sSo8RLMRealmC13configuration5queueABSo0A13ConfigurationC_So012OS_dispatch_C0CSgtKcfCTO + 128
11  Project                            0x0000000102bddb18 $s10RealmSwift0A0V13configuration5queueA2C13ConfigurationV_So012OS_dispatch_D0CSgtKcfC + 204
12  Project                            0x00000001024817a4 $s8Project18BaseLocalDataStoreC5realm10RealmSwift0I0VSgvg + 240
13  Project                            0x00000001024929f4 $s8Project40ThirdPartyConnectedServiceLocalDataStoreC12bindDelegate06outputL0yAA0defghiJ14OutputProtocol_p_tF + 252
14  Project                            0x0000000102493138 $s8Project40ThirdPartyConnectedServiceLocalDataStoreCAA0defghiJ8ProtocolA2aDP12bindDelegate06outputM0yAA0defghij6OutputK0_p_tFTW + 28
15  Project                            0x00000001022e9b14 $s8Project27ThirdPartyServiceRepositoryC15remoteDataStore05localiJ0AcA0def6RemoteiJ8Protocol_p_AA0de9Connectedf5LocalijM0_ptcfc + 232
16  Project                            0x00000001022e9a1c $s8Project27ThirdPartyServiceRepositoryC15remoteDataStore05localiJ0AcA0def6RemoteiJ8Protocol_p_AA0de9Connectedf5LocalijM0_ptcfC + 64
17  Project                            0x000000010237ae20 $s8Project14UserRepositoryC14sharedInstance_WZ + 448
18  libdispatch.dylib                   0x000000010f7027c0 _dispatch_client_callout + 20
19  libdispatch.dylib                   0x000000010f704364 _dispatch_once_callout + 136
20  Project                            0x000000010237af50 $s8Project14UserRepositoryC14sharedInstanceAA0dE8Protocol_pvau + 76
21  Project                            0x00000001020ad2d8 $s8Project18UserSessionManagerC14sharedInstance_WZ + 44
22  libdispatch.dylib                   0x000000010f7027c0 _dispatch_client_callout + 20
23  libdispatch.dylib                   0x000000010f704364 _dispatch_once_callout + 136
24  Project                            0x00000001020ad398 $s8Project18UserSessionManagerC14sharedInstanceACvau + 76
25  Project                            0x00000001021d1828 $s8Project11AppDelegateCACycfc + 172
26  Project                            0x00000001021d19c4 $s8Project11AppDelegateCACycfcTo + 20
27  UIKitCore                           0x000000019909a450 3ED35565-456D-33CB-B554-6C567FA81585 + 16090192
28  UIKitCore                           0x00000001983d7d74 UIApplicationMain + 336
29  Project                            0x00000001021d2530 main + 64
30  dyld                                0x000000010ec85ce4 start + 520!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose

Steps & Code to Reproduce

  1. Configure iOS project and using Realm there
  2. Add Kotlin Multiplatform library with Realm usage
  3. Try to install app through Xcode

P.S. This issue is reproduced only when it's a fresh install (app is not installed in the device yet)

AlexIzh avatar Aug 08 '22 09:08 AlexIzh

Hi @AlexIzh I would not recommend mixing these two SDK's together, for the reason being that the Realm Core versions they use are misaligned.

leemaguire avatar Aug 11 '22 07:08 leemaguire

@leemaguire Using different core versions should not result in this kind of error. Is this somehow reproducible by you? I would like to know why this fails.

jedelbo avatar Aug 30 '22 08:08 jedelbo

Hi @AlexIzh. Can you shed some light on the realm usage in the app? What realm files are involved and how/when are they accessed?

Further, what is the KMP part of the app doing? We don't have a version 12.1.0 of the Realm Kotlin SDK, so what are you referring to as the KMP SDK?

rorbech avatar Aug 30 '22 11:08 rorbech

Hello @AlexIzh any update on this issue?

nicola-cab avatar Sep 20 '22 15:09 nicola-cab

Oh sorry, we decided to move to Sqlite on KMP part since seems like Realm doesn't support to be used on both side at the same time. We are just migrating our codebase from iOS/Android parts to use some shared library (KMP) that contains database storage. In IOS app we just use it like a regular database. KMP part of the app stores different information in the other database file (we used different realm name and all configurations (path, scheme, objects, etc)).

Regarding Kotlin SDK: I'm very sorry, it was my mistake, it was Core Realm SDK version that used in Kotlin SDK.

AlexIzh avatar Sep 20 '22 16:09 AlexIzh

Hello @AlexIzh, thanks for your response. It should be absolutely fine to use realm from 2 different applications or SDKs and be able to share data via the database, provided the 2 SDKs are not using completely incompatible file formats, and they share the same schema.

In your case, I don't believe this is the case, IOS SDK is using realm core 12.4.0 and Kotlin SDK is using 12.1.0, which use the same file format (v22). So you should be able to do that.

Maybe @rorbech can give us more feedback here, I am not sure how to configure my environment in order to reproduce the issue, but I can try :-)

nicola-cab avatar Sep 20 '22 17:09 nicola-cab

Also, @AlexIzh if you have a code sample to provide in order to help us to reproduce the issue, please share this with us. It would help us a lot. Thank you.

nicola-cab avatar Sep 21 '22 09:09 nicola-cab