-
Type: Bug
-
Resolution: Duplicate
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
Goals
Try to open a realm file in global dispatch queue.
Expected Results
Realm is open, or throw an Swift Error.
Actual Results
Crashed in Realm.init().
BACKGROUND THREAD 2 - CRASHED libsystem_kernel.dylib __pthread_kill libsystem_c.dylib abort Libraries_iOS please_report_this_issue_in_github_realm_realm_core __hidden#12016_:50 Libraries_iOS _hidden#12012_ __hidden#12016_:123 Libraries_iOS realm::util::terminate_with_info(char const*, char const*, long, char const*, std::initializer_list<realm::util::Printable>&&) __hidden#12016_:151 Libraries_iOS void realm::util::terminate_with_info<unsigned long long const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(char const*, int, char const*, char const*, unsigned long long const&&&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&) __hidden#59_:52 Libraries_iOS realm::SlabAlloc::attach_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, realm::SlabAlloc::Config&) __hidden#248_:0 Libraries_iOS realm::DB::do_open(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, bool, realm::DBOptions) __hidden#2732_:1023 Libraries_iOS realm::DB::open(realm::Replication&, realm::DBOptions) __hidden#2732_:1365 Libraries_iOS realm::DB::create(realm::Replication&, realm::DBOptions) __hidden#2732_:2735 Libraries_iOS realm::_impl::RealmCoordinator::open_db() __hidden#1424_:489 Libraries_iOS realm::_impl::RealmCoordinator::do_get_realm(realm::Realm::Config, std::__1::shared_ptr<realm::Realm>&, realm::util::Optional<realm::VersionID>, realm::util::CheckedUniqueLock&) __hidden#1424_:316 Libraries_iOS realm::_impl::RealmCoordinator::get_realm(realm::Realm::Config, realm::util::Optional<realm::VersionID>) __hidden#1424_:288 Libraries_iOS realm::Realm::get_shared_realm(realm::Realm::Config) __hidden#5480_:129 Libraries_iOS _hidden#9561_ __hidden#9754_:440 Libraries_iOS RealmSwift.Realm.init(configuration: RealmSwift.Realm.Configuration, queue: __C.OS_dispatch_queue?) throws -> RealmSwift.Realm __hidden#472_:0 Libraries_iOS ... // let realm = try Realm() libdispatch.dylib _dispatch_call_block_and_release
Steps for others to Reproduce
This crash was collected through analytics and affects about 1% of users. I was unable to reproduce the issue in a development environment. However, the crash occurs 100% of the time for users who are already experiencing the problem. So I guess the crash is related to the content of the database file.
It seems that there is another similar case here: https://github.com/realm/realm-cocoa/issues/6699#issuecomment-812846482 (Same call stack and realm version, but crash in main thread. So I guess this crash is not a multi-threading problem.)
Crash Point
// this function is called in DispatchQueue.global().async { } and with a do-try-catch block func foo() throws { var conf = Realm.Configuration.defaultConfiguration conf.fileURL = someDatabaseFileUrl let realm = try Realm(configuration: conf) // <= crashed ... }
The database file I try to open is previously generated by the following code snippet. I'm not sure if it will help to solve the problem.
let realm = try Realm(configuration: configuration) try realm.writeCopy(toFile: databaseUrl)
Version of Realm and Tooling
Realm framework version: 10.7.2 (core 10.5.5)
Realm Object Server version: N/A
Xcode version: 12.4
iOS version: 14.4 / 14.4.1 / 14.4.2
Dependency manager: Xcode 12.4 built-in Swift Package Manager