-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
How frequently does the bug occur?
Sometimes
Description
While retrieving and updating a Realm object, the app intermittently crashes with an EXC_BAD_ACCESS exception, pointing to __cxx_atomic_store. 9 out of 10 times everything works as expected.
Below is relevant code for one of the instances of this error. The app throws an exception at the Realm.object(ofType:forPrimaryKey) call in the latter helper function.
struct AgendaStatusData: Decodable { @discardableResult func process(on api: API) async throws { guard let userId = api.userId else { throw APIError.notLoggedIn } let realm = await api.realm try await realm.update(DBUser.self, id: userId) { user in // Update user data } } } // Helper functions extension Realm { public func update<O: Object & Identifiable, Result>(_ type: O.Type, id: O.ID, _ block: (O) throws -> Result) async throws -> Result { let object = try get(O.self, id: id).safeThaw() return try await self.asyncWrite { try block(object) } } public func get<O: Object & Identifiable>(_ object: O.Type, id: O.ID) throws -> O { guard let result = self.object(ofType: O.self, forPrimaryKey: id) else { throw AppError.databaseError(.invalidObjectReference(O.itemInfo(id: id))) } return result } }
Stacktrace & log output
Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
#0 0x000000010311b97c in void std::__1::__cxx_atomic_store[abi:v15006]<realm::Table*>(std::__1::__cxx_atomic_base_impl<realm::Table*>*, realm::Table*, std::__1::memory_order) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.4.sdk/usr/include/c++/v1/atomic:945 #1 0x000000010311b90c in std::__1::__atomic_base<realm::Table*, false>::store[abi:v15006](realm::Table*, std::__1::memory_order) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.4.sdk/usr/include/c++/v1/atomic:1552 #2 0x000000010311b8d8 in void std::__1::atomic_store_explicit[abi:v15006]<realm::Table*>(std::__1::atomic<realm::Table*>*, std::__1::atomic<realm::Table*>::value_type, std::__1::memory_order) at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.4.sdk/usr/include/c++/v1/atomic:1906 #3 0x000000010310b724 in void realm::util::store_atomic<realm::Table*>(realm::Table*&, realm::Table*, std::__1::memory_order) at /Users/***/Library/Developer/Xcode/DerivedData/App-gieupfwmgkxfrjaauikcpstmrmdx/SourcePackages/checkouts/realm-core/src/realm/util/thread.hpp:812 #4 0x000000010310aa4c in realm::Group::create_table_accessor(unsigned long) at /Users/***/Library/Developer/Xcode/DerivedData/App-gieupfwmgkxfrjaauikcpstmrmdx/SourcePackages/checkouts/realm-core/src/realm/group.cpp:793 #5 0x000000010310a5d4 in realm::Group::do_get_table(unsigned long) at /Users/***/Library/Developer/Xcode/DerivedData/App-gieupfwmgkxfrjaauikcpstmrmdx/SourcePackages/checkouts/realm-core/src/realm/group.cpp:663 #6 0x0000000102bdddf4 in realm::Group::get_table(realm::TableKey) at /Users/***/Library/Developer/Xcode/DerivedData/App-gieupfwmgkxfrjaauikcpstmrmdx/SourcePackages/checkouts/realm-core/src/realm/group.hpp:960 #7 0x0000000102cb7478 in realm::Object realm::Object::get_for_primary_key<objc_object* __strong, RLMAccessorContext>(RLMAccessorContext&, std::__1::shared_ptr<realm::Realm> const&, realm::ObjectSchema const&, objc_object* __strong) at /Users/***/Library/Developer/Xcode/DerivedData/App-gieupfwmgkxfrjaauikcpstmrmdx/SourcePackages/checkouts/realm-core/src/realm/object-store/object_accessor.hpp:390 #8 0x0000000102cb7190 in RLMGetObject at /Users/***/Library/Developer/Xcode/DerivedData/App-gieupfwmgkxfrjaauikcpstmrmdx/SourcePackages/checkouts/realm-swift/Realm/RLMObjectStore.mm:226 #9 0x0000000102f8001c in Realm.object<τ_0_0, τ_0_1>(ofType:forPrimaryKey:) at /Users/***/Library/Developer/Xcode/DerivedData/App-gieupfwmgkxfrjaauikcpstmrmdx/SourcePackages/checkouts/realm-swift/RealmSwift/Realm.swift:794 #10 0x0000000103c8ef70 in Realm.get<τ_0_0>(_:id:) at *** #11 0x0000000103c90c18 in Realm.update<τ_0_0, τ_0_1>(_:id:_:) at *** #12 0x00000001039724dc in AgendaStatusData.process(on:) at *** #13 0x0000000103996678 in closure #1 in API.updateAgendas() at *** #14 0x00000001039969e0 in partial apply for closure #1 in API.updateAgendas() () #15 0x000000010399dc48 in closure #1 in API.startJob<τ_0_0, τ_0_1>(_:item:block:) at *** #16 0x000000010399e480 in partial apply for closure #1 in API.startJob<τ_0_0, τ_0_1>(_:item:block:) ()
Can you reproduce the bug?
Sometimes
Reproduction Steps
No response
Version
10.42.0
What Atlas Services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
iOS 16.4
Build environment
Xcode version: 14.3 (14E222b)
Dependency manager and version: SPM