realm-swift: Crash in verifier method when using `preconditionIsolated` with iOS 17
How frequently does the bug occur?
Always
Description
I am encountering a crash when using the latest version of Realm and attempting to fetch objects from DB. This issue arises specifically on iOS 17.
To provide some context, I have implemented a Realm actor called RealmActor. Below is an example of the code structure:
actor RealmActor {
var realm: Realm!
init() async throws {
realm = try await Realm(actor: self)
}
var count: Int {
realm.objects(Todo.self).count
}
}
The crash occurs within the verifier method, which is associated with the preconditionIsolated call.
#if swift(>=5.9)
// When possible use the official API for actor checking
if #available(macOS 14.0, iOS 17.0, tvOS 17.0, watchOS 10.0, *) {
return {
self.preconditionIsolated()
}
}
#endif
I would greatly appreciate it if this issue could be investigated and addressed in a future release. If any additional information is needed to assist with debugging or reproducing the issue, please let me know.
Thank you for your attention to this matter, and I look forward to a resolution.
Stacktrace & log output
RealmSwift/Realm.swift:1469: Precondition failed: Incorrect actor executor assumption; Expected 'UnownedSerialExecutor(executor: (Opaque Value))' executor.
Can you reproduce the bug?
Always
Reproduction Steps
Fetch objects from the DB, using Actor
Version
10.40.2
What Atlas Services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
iOS 17
Build environment
Xcode version: 15.0 beta (15A5160n) Dependency manager and version: SPM
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 19 (4 by maintainers)
@buildnewmac It took me a long time to solve this because the crash didn’t have a great trace. I ended up going call by call everywhere I was accessing realm. There was one place that I was calling it from a different TaskGroup, or DistpatchQueue. I have no clue why this worked in iOS 16, but in iOS 17 it was crashing. My suggestions is to very closely look at each call you make to each of your realms and make sure they’re calling on the exact same thread
On iOS 16 we can only detect invalid use of Realms outside of the actor if you manually enable actor data race detection in your project.