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

EXC_BAD_ACCESS on version 5.x.x #6626

Closed
tristangrichard opened this issue Jul 3, 2020 · 12 comments
Closed

EXC_BAD_ACCESS on version 5.x.x #6626

tristangrichard opened this issue Jul 3, 2020 · 12 comments
Assignees

Comments

@tristangrichard
Copy link

tristangrichard commented Jul 3, 2020

!!! MANDATORY TO FILL OUT !!!

Actual Results

Crashes in

static uint_least8_t get_width_from_header(const char* header) noexcept
    {
        typedef unsigned char uchar;
        const uchar* h = reinterpret_cast<const uchar*>(header);
        return uint_least8_t((1 << (int(h[4]) & 0x07)) >> 1);
    }

Version of Realm and Tooling

Realm framework version: 5.0.3 and 5.2.0
Xcode version: 11.5

iOS/OSX version: iOS 12 and 13

Dependency manager + version: SPM

@raphaelcruzeiro
Copy link

Our app is crashing on lauch 4 out of 5 times due to this.

@bmunkholm
Copy link
Contributor

@raphaelcruzeiro @trr-amsiq Can you please provide details of the crashes? And if this is reproducible, can you try to make a minimal reprocase?

@raphaelcruzeiro
Copy link

raphaelcruzeiro commented Jul 6, 2020

@bmunkholm I have EXC_BAD_ACCESS happening all over the place since the 5.x.x update. I've actually copied a stacktrace to the other EXC_BAD_ACCESS issue (#6555) since it seems it's the same method that is crashing. I'm trying to get all the stacktraces but they are taking a while to arrive since the app is crashing on lauch.

So far I've observed EXC_BAD_ACCESS on the following spots:

  • realm::util::EncryptedFileMapping::read_barrier(void const*, unsigned long, unsigned long (*)(char const*))
  • realm::ArrayString::get(char const*, unsigned long, realm::Allocator&)

I'll post to this thread again if I get the stacktrace for static uint_least8_t get_width_from_header(const char* header) noexcept

Also, I can't be 100% sure if this is related, but we started receiving quite a lot of Out Of Memory exceptions since we updated to 5.x.x.

@tristangrichard
Copy link
Author

tristangrichard commented Jul 16, 2020

This is the stacktrace on app launch with 5.3.0. from 4.4.1.

#0	0x0000000101ecd608 in realm::NodeHeader::get_width_from_header(char const*) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/node_header.hpp:106
#1	0x0000000101eda2d8 in realm::Node::init_from_mem(realm::MemRef) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/node.hpp:132
#2	0x0000000101eda1f8 in realm::Array::init_from_mem(realm::MemRef) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/array.cpp:223
#3	0x0000000101c4fa24 in realm::Array::init_from_ref(unsigned long) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/array.hpp:169
#4	0x0000000101e10674 in realm::ArrayKeyBase<1>::init_from_ref(unsigned long) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/array_key.hpp:59
#5	0x000000010202e1e0 in realm::Cluster::init_leaf(realm::ColKey, realm::ArrayPayload*) const at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/cluster.cpp:1519
#6	0x00000001022260d0 in realm::LinkMap::set_cluster(realm::Cluster const*) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/query_expression.hpp:1863
#7	0x0000000102228e20 in realm::Columns<realm::Link>::set_cluster(realm::Cluster const*) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/query_expression.hpp:2670
#8	0x0000000101e6f1ec in realm::Compare<realm::NotEqual, realm::ObjKey, realm::Subexpr, realm::Subexpr>::set_cluster(realm::Cluster const*) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/query_expression.hpp:3852
#9	0x000000010221b498 in realm::ExpressionNode::cluster_changed() at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/query_engine.cpp:568
#10	0x000000010211f674 in realm::ParentNode::set_cluster(realm::Cluster const*) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/query_engine.hpp:211
#11	0x000000010211feb8 in realm::Query::find_all(realm::ConstTableView&, unsigned long, unsigned long, unsigned long) const::$_4::operator()(realm::Cluster const*) const at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/query.cpp:1354
#12	0x000000010211fe18 in realm::util::FunctionRef<bool (realm::Cluster const*)>::FunctionRef<realm::Query::find_all(realm::ConstTableView&, unsigned long, unsigned long, unsigned long) const::$_4&>(realm::Query::find_all(realm::ConstTableView&, unsigned long, unsigned long, unsigned long) const::$_4&)::'lambda'(void*, realm::Cluster const*)::operator()(void*, realm::Cluster const*) const at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/util/function_ref.hpp:64
#13	0x000000010211fdd4 in realm::util::FunctionRef<bool (realm::Cluster const*)>::FunctionRef<realm::Query::find_all(realm::ConstTableView&, unsigned long, unsigned long, unsigned long) const::$_4&>(realm::Query::find_all(realm::ConstTableView&, unsigned long, unsigned long, unsigned long) const::$_4&)::'lambda'(void*, realm::Cluster const*)::__invoke(void*, realm::Cluster const*) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/util/function_ref.hpp:63
#14	0x000000010202a630 in realm::util::FunctionRef<bool (realm::Cluster const*)>::operator()(realm::Cluster const*) const at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/util/function_ref.hpp:77
#15	0x00000001020341c0 in realm::util::FunctionRef<bool (realm::Cluster const*)>::FunctionRef<realm::util::FunctionRef<bool (realm::Cluster const*)>&>(realm::util::FunctionRef<bool (realm::Cluster const*)>&)::'lambda'(void*, realm::Cluster const*)::operator()(void*, realm::Cluster const*) const at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/util/function_ref.hpp:64
#16	0x000000010203417c in realm::util::FunctionRef<bool (realm::Cluster const*)>::FunctionRef<realm::util::FunctionRef<bool (realm::Cluster const*)>&>(realm::util::FunctionRef<bool (realm::Cluster const*)>&)::'lambda'(void*, realm::Cluster const*)::__invoke(void*, realm::Cluster const*) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/util/function_ref.hpp:63
#17	0x000000010202a630 in realm::util::FunctionRef<bool (realm::Cluster const*)>::operator()(realm::Cluster const*) const at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/util/function_ref.hpp:77
#18	0x0000000102032230 in realm::ClusterTree::traverse(realm::util::FunctionRef<bool (realm::Cluster const*)>) const at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/cluster.cpp:2041
#19	0x000000010210f72c in realm::Table::traverse_clusters(realm::util::FunctionRef<bool (realm::Cluster const*)>) const at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/table.hpp:319
#20	0x000000010210fcfc in realm::Query::find_all(realm::ConstTableView&, unsigned long, unsigned long, unsigned long) const at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/query.cpp:1368
#21	0x00000001022b0bc8 in realm::ConstTableView::do_sync() at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/table_view.cpp:602
#22	0x000000010210fec4 in realm::Query::find_all(unsigned long, unsigned long, unsigned long) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/query.cpp:1380
#23	0x0000000102110438 in realm::Query::find_all(realm::DescriptorOrdering const&) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-core/src/realm/query.cpp:1467
#24	0x0000000101d212a4 in realm::Results::do_evaluate_query_if_needed(bool) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-cocoa/Realm/ObjectStore/src/results.cpp:383
#25	0x0000000101d294bc in realm::Results::evaluate_query_if_needed(bool) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-cocoa/Realm/ObjectStore/src/results.cpp:360
#26	0x0000000101eafd44 in -[RLMResults countByEnumeratingWithState:objects:count:]::$_5::operator()() const at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-cocoa/Realm/RLMResults.mm:183
#27	0x0000000101eabc0c in auto translateRLMResultsErrors<-[RLMResults countByEnumeratingWithState:objects:count:]::$_5>(-[RLMResults countByEnumeratingWithState:objects:count:]::$_5&&, NSString*) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-cocoa/Realm/RLMResults_Private.hpp:60
#28	0x0000000101eabbbc in -[RLMResults countByEnumeratingWithState:objects:count:] at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-cocoa/Realm/RLMResults.mm:182
#29	0x00000001bd1191b0 in NSFastEnumerationIterator.next() ()
#30	0x000000010234e004 in RLMIterator.next() at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-cocoa/RealmSwift/RealmCollection.swift:34
#31	0x000000010234e5e8 in protocol witness for IteratorProtocol.next() in conformance RLMIterator<A> ()
#32	0x000000010232c6bc in List.append<A>(objectsIn:) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-cocoa/RealmSwift/List.swift:270
#33	0x0000000101490018 in static Image.loadOfflineImages(realm:account_id:) at /Users/trr/workspace/App-ios/App/Models/Account/Image.swift:65
#34	0x000000010130b3cc in static Account.parseAndPersist(json:realm:duplicateListDateTime:) at /Users/trr/workspace/App-ios/App/Models/Account/Account.swift:214
#35	0x0000000100dcb75c in closure #1 in static AccountCollection.parse(_:realm:) at /Users/trr/workspace/App-ios/App/Models/Collection/AccountCollection.swift:51
#36	0x000000010146adb0 in thunk for @callee_guaranteed (@guaranteed JSON) -> (@error @owned Error) ()
#37	0x0000000100dd0b60 in partial apply for thunk for @callee_guaranteed (@guaranteed JSON) -> (@error @owned Error) ()
#38	0x00000001942f0644 in Sequence.forEach(_:) ()
#39	0x0000000100dcb348 in static AccountCollection.parse(_:realm:) at /Users/trr/workspace/App-ios/App/Models/Collection/AccountCollection.swift:50
#40	0x0000000100dcbce8 in closure #1 in static AccountCollection.store(realm:data:realmKey:initial:filter:) at /Users/trr/workspace/App-ios/App/Models/Collection/AccountCollection.swift:66
#41	0x0000000100e83cf8 in Realm.safeWrite(_:) at /Users/trr/workspace/App-ios/App/Extensions/Realm.swift:28
#42	0x0000000100dcba94 in static AccountCollection.store(realm:data:realmKey:initial:filter:) at /Users/trr/workspace/App-ios/App/Models/Collection/AccountCollection.swift:65
#43	0x00000001015c3f9c in closure #1 in closure #2 in closure #1 in static MatchAPI.getMatches(initial:cursor:tag:) at /Users/trr/workspace/App-ios/App/Pages/Feature/Match/MatchAPI.swift:28
#44	0x0000000100e8479c in thunk for @callee_guaranteed () -> (@error @owned Error) ()
#45	0x0000000100e847fc in partial apply for thunk for @callee_guaranteed () -> (@error @owned Error) ()
#46	0x00000001023482bc in Realm.write<A>(withoutNotifying:_:) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/realm-cocoa/RealmSwift/Realm.swift:227
#47	0x0000000100e83d94 in Realm.safeWrite(_:) at /Users/trr/workspace/App-ios/App/Extensions/Realm.swift:30
#48	0x00000001015c3e64 in closure #2 in closure #1 in static MatchAPI.getMatches(initial:cursor:tag:) at /Users/trr/workspace/App-ios/App/Pages/Feature/Match/MatchAPI.swift:27
#49	0x0000000100e8479c in thunk for @callee_guaranteed () -> (@error @owned Error) ()
#50	0x00000001015c54b4 in partial apply for thunk for @callee_guaranteed () -> (@error @owned Error) ()
#51	0x00000001bd2aebcc in autoreleasepool<A>(invoking:) ()
#52	0x00000001015c3b18 in closure #1 in static MatchAPI.getMatches(initial:cursor:tag:) at /Users/trr/workspace/App-ios/App/Pages/Feature/Match/MatchAPI.swift:25
#53	0x0000000101925c8c in closure #1 in ObservableType.do(onNext:afterNext:onError:afterError:onCompleted:afterCompleted:onSubscribe:onSubscribed:onDispose:) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/RxSwift/Sources/RxSwift/Do.swift:31
#54	0x0000000101926140 in partial apply for closure #1 in ObservableType.do(onNext:afterNext:onError:afterError:onCompleted:afterCompleted:onSubscribe:onSubscribed:onDispose:) ()
#55	0x0000000101926c90 in DoSink.on(_:) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/RxSwift/Sources/RxSwift/Do.swift:66
#56	0x0000000101927764 in protocol witness for ObserverType.on(_:) in conformance DoSink<A> ()
#57	0x000000010196246c in ObserveOnSink.run(_:_:) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/RxSwift/Sources/RxSwift/ObserveOn.swift:117
#58	0x0000000101965d68 in partial apply for ObserveOnSink.run(_:_:) ()
#59	0x000000010196266c in thunk for @escaping @callee_guaranteed (@unowned @callee_guaranteed () -> ()) -> () ()
#60	0x0000000101983580 in thunk for @escaping @callee_guaranteed (@in_guaranteed A, @unowned @callee_guaranteed (@in_guaranteed A) -> ()) -> () ()
#61	0x0000000101983668 in thunk for @escaping @callee_guaranteed (@in_guaranteed A, @in_guaranteed @callee_guaranteed (@in_guaranteed A) -> (@out ())) -> (@out ()) ()
#62	0x00000001019831e0 in closure #1 in RecursiveImmediateScheduler.schedule(_:) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/RxSwift/Sources/RxSwift/RecursiveScheduler.swift:191
#63	0x000000010191ee20 in closure #1 in DispatchQueueConfiguration.schedule<A>(_:action:) at /Users/trr/Library/Developer/Xcode/DerivedData/App-gqpdkptibocowffxsuwzfslmjhcf/SourcePackages/checkouts/RxSwift/Sources/RxSwift/DispatchQueueConfiguration.swift:27

The code causing the crash is and is within a write transaction:

let offlineImages = realm.objects(Image.self).filter("imageUpload != nil && shouldBeDeleted == false && account_id == %@", account_id)
let list = List<Image>()
list.append(objectsIn: offlineImages) <-- This

@bguidolim
Copy link

Seems to be related to #6555

@jedelbo
Copy link

jedelbo commented Jul 17, 2020

@raphaelcruzeiro @trr-amsiq are you running with encryption enabled?

@tristangrichard
Copy link
Author

It is a no from here

@raphaelcruzeiro
Copy link

@jedelbo also not enabled here

@jedelbo
Copy link

jedelbo commented Jul 17, 2020

@raphaelcruzeiro @trr-amsiq ok - then this is not encryption related.
I assume this error only happens on a device where you upgrade an already existing file. The error does not occur if the database is created from fresh using version 5.2.0. Can you confirm this?
It would be nice to know if you are able to reproduce this error on a device where you are able to get hold of the realm file. Either after the crash has happened or - ideally - both before the upgrade and after the crash. It would really help if you can send me some realm files for examination. You can send them privately to me at jorgen.edelbo (at) mongodb.com.

@tristangrichard
Copy link
Author

I tried both scenarios and it doesn't matter if the file was upgraded or not. I will try to get you the realm files. Don't expect them today.

@tristangrichard
Copy link
Author

tristangrichard commented Jul 17, 2020

I tried reproducing the crash on a simulator. It just won't happen.
I can reproduce it on device but the realm file is not in the container /AppData/Documents folder.
Realm is shared with app extensions using App Groups

@tgoyne
Copy link
Member

tgoyne commented Jul 21, 2020

Probably fixed by realm/realm-core#3828.

@tgoyne tgoyne closed this as completed Jul 21, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 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

6 participants