-
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
Null pointer crash in create_object_with_primary_key
every time for certain DB
#7641
Comments
Hi @tfe in order to reproduce this issue, would you mind sharing your |
Hi @dianaafanador3, thanks! I can provide those. I put together a gist with the relevant files, with less relevant parts trimmed for length and readability. I still included the functions responsible for initial creation of the realm by copying the seed data realm. Here are some details to help you navigate the files in the gist:
This will be in DataManager.swift, look in the
This will be in DataManager.swift as well, look in the
I've included Course.swift in the gist, stripped down to just show the properties and how we're mapping them from the server response using ObjectMapper. |
@dianaafanador3 Just checking in on this. Can I provide anything else to help? |
What happens in The curious thing about the Maybe using |
@ericjordanmossman I'll paste the code for that function (and related) below. I agree that it seems like something is going wrong with the file, however it's not because it's old. As I mentioned, it happens even on fresh installs:
If I provided the Realm file that's exhibiting this behavior, would you or your team be able to analyze them to see what's going on to trigger the Here are the relevant parts of the struct containing struct RealmConfigData {
let fileName: String
var dataFileName: String {
return "\(fileName)\(EnvironmentManager.shared.dataStoreSuffix).realm"
}
var fileURL: URL {
return Realm.Configuration.defaultConfiguration.fileURL!
.deletingLastPathComponent()
.appendingPathComponent(dataFileName)
}
func overwriteFile(with realm: Realm) throws {
// first remove existing if present
do {
try FileManager.default.removeItem(at: fileURL)
} catch CocoaError.fileNoSuchFile {
// This is fine; the file isn't always there. Continue.
}
try realm.writeCopy(toFile: fileURL, encryptionKey: Self.encryptionKeyData(from: encryptionKey))
}
} |
Hi @tfe If you can send us a copy of the corrupted realm we may diagnose the issue. Please send it to diana.perez@mongodb.com |
@dianaafanador3 Thanks so much! Sent it to you via email. |
Hi @tfe we were not able to decrypt your realm realm file, which could mean that the file is completely corrupted. Have you tried downgrading to |
@tfe can you show us what the implementation of |
When this crash occurs, are you using Realm on any other thread? Are you able to provide more stack traces? |
@dianaafanador3 It opens without complaint in my app (only crashing when trying to create an object), so I'm not sure what to say there. @leemaguire I don't have any more stack traces, sorry. This never got shipped to more than one or two users before we saw the issue, so I don't have any others. I'll paste Regarding threads: yes, it's possible... I mentioned the process where we update the data in this realm (by deleting most objects, downloading, decoding, and then adding a new object tree). After that completes, we kick off a task on a background thread to clean up orphaned objects. static func encryptionKeyData(from key: String?) -> Data? {
guard let key = key else { return nil }
return key.data(using: String.Encoding.utf8, allowLossyConversion: false)
} |
Moved to realm/realm-core#5397 |
How frequently does the bug occur?
All the time
Description
This started happening after updating from Realm 10.7.5 to 10.21.1 (and does not happen if I revert back to 10.7.5).
The database regularly gets into a state where any object creation will crash, every time. I've reduced the app down to the most minimal case, doing nothing upon launch but the following, and it still does it.
If I delete the app bundle and re-install, it might work a couple times but pretty quickly gets into whatever corrupt state is causing this, after which it's unusable until it's deleted and recreated.
This tells me there is something wrong with the database files, so I've preserved those and would be happy to provide those privately for analysis to solve this bug.
In case it's relevant, the way we use this database is that it's created by copying a seed database containing large object tree (the "course"). This part is working fine. The problem starts happening when we do an operation to update the data, which involves clearing the database (deleting all objects) before downloading, decoding, and then adding the new object tree to the realm.
This makes me suspect something in the deletion as the root cause, but I'm hoping inspection of my Realm data files will make it obvious what's wrong with them.
Stacktrace & log output
Can you reproduce the bug?
Yes, always
Reproduction Steps
As I mentioned, it seems to be something with the specific database, so the most relevant thing for reproducing is those files which I can provide privately.
Version
10.21.1
What SDK flavour are you using?
Local Database only
Are you using encryption?
Yes, using encryption
Platform OS and version(s)
iOS 14 and 15
Build environment
Version 13.2.1 (13C100)
Dependency manager and version: cocoa pods
The text was updated successfully, but these errors were encountered: