-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Results and objects are not isFrozen
after calling freeze()
#7697
Comments
Hi @dianaafanador3, sure thing, the query function is pasted below along with the others it calls. It's pretty simple. I did try updating recently but had a rash of unexplained issues [1] [2], and so ended up staying on v10.7.5. I'm sure freezing is working fine in general on all versions (it's covered in the test suite). Yet I have this reproducible case where it fails every time, so there must exist some edge case where The question is, under what conditions can that happen? (And then, how to fix or avoid it.) I do have a copy of the customer's DB file that this is happening with. If you'd like to see it I can get their consent to share it with you. // Model.swift
static func modifiedSince(date: Date) -> Results<Model> {
let dm = DataManager.forCurrentThread()
let nsDate = date as NSDate
return dm.all(self).filter("endedAt >= %@", nsDate)
}
// DataManager.swift
func all<T: Object>(_ type: T.Type, in db: Database = .main) -> Results<T> {
return getRealm(for: db).objects(type)
}
// getRealm(for:) returns a Realm instance created by calling realm's `Realm(configuration:)` initializer [1] #7641 |
@tfe could you supply us with a sample project that reproduces the issue, we cannot reproduce the issue from our end. |
@leemaguire Yes, I can get something together for you. One additional bit of info: this seems to only be happening on first open of a Realm created via the |
Hi @tfe did you get a chance to get the reproduction case together? I still cannot reproduce when testing against a freshly frozen realm from |
Hi @tfe did you get the chance to get the reproduction case?, It will very helpful so we can reproduce this. |
@dianaafanador3 @leemaguire I have a reproduction case for you (I'll email it to Diana separately, since I have her address). If you run it it should crash on launch, and that will point you to the place where As I mentioned previously, I'm getting a crash on first open of a realm created via Please let me know if you have any questions about the example project, or if it's not behaving as described here. |
@tfe Thanks for the reproduction case, I'm looking into the issue now. |
Thanks @leemaguire! Glad you were able to find the root cause. |
Hi. It seems this bug resurfaces when freezing a realm opened as read only. Can this bug be fixed? |
Hi @joaocolaco why are you using freeze with a read-only realm, the purpose of freeze is get an immutable snapshot of the realm data, and that's what a read-only realm is.
|
Thanks! As for the use case freeze is also useful for querying the database in other threads, something that I need to do in my app (due to calls from SwiftUI and Swift async). This particular database is in the Bundle Resources of the app so it shouldn't never be written. When the first version of the app was made the frozen functionality wasn't available so it was opened as read-only. When Can I make a feature suggestion? Why not make all the read-only realms frozen? That would give "free" functionality and remove this sort of confusions. |
Hi @joaocolaco can you open a new issue?, as it seems this is unrelated to the original one and we can follow from there. |
How frequently does the bug occur?
All the time
Description
I recently implemented a feature that depends on using
freeze()
to pass a Results object to another thread for further processing, however I'm seeing crashes due to accessing from an incorrect thread.This was unexpected since freezing the collection should have prevented this error. In debugging I added some diagnostic print statements to see what was going on:
The same thing happens even if I freeze the objects individually and store them in a regular array:
If I let it continue past this point and access the objects or Results on another thread, it crashes with an incorrect thread exception.
Is this expected behavior? Or am I misunderstanding how freezing objects works?
Stacktrace & log output
No response
Can you reproduce the bug?
Yes, always
Reproduction Steps
I can provide more on this, but first I wanted to make sure I'm not just misunderstanding how the feature is designed to be used.
Version
10.7.5
What SDK flavour are you using?
Local Database only
Are you using encryption?
No, not using encryption
Platform OS and version(s)
iPadOS 15
Build environment
Xcode version: 13.2
Dependency manager and version: Cocoapods
The text was updated successfully, but these errors were encountered: