realm-swift icon indicating copy to clipboard operation
realm-swift copied to clipboard

Realm Core realm::util::terminate_internal Crashes

Open henry2423 opened this issue 2 years ago • 6 comments

How frequently does the bug occur?

All the time

Description

We keep seeing some users get repetitive crashes when the Realm booting up. I wonder whether there is a way to prevent the abort() function called from realm-core?

CleanShot 2022-08-15 at 14 09 28@2x CleanShot 2022-08-15 at 14 09 23@2x

Stacktrace & log output

As the attached screenshots.

Can you reproduce the bug?

Not yet

Reproduction Steps

Can't reproduce it, but we keep seeing the crash stack from the Xcode organizer.

Version

10.28.0

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

iOS 14&15

Build environment

Xcode version: Xcode 13.4.1 Dependency manager and version: Cocoapods

henry2423 avatar Aug 15 '22 21:08 henry2423

Hi @henry2423. The abort cannot be avoided. Could you show us your migration script? Either here or through [email protected]. Hopefully by looking at that we will get a better understanding of what might cause the issue.

leemaguire avatar Aug 19 '22 10:08 leemaguire

Here is my Realm configuration

var configuration: Realm.Configuration
configuration = Realm.Configuration()
let currentFolder = environment.currentFolder()
configuration.fileURL = currentFolder.url(forFile: Self.databaseFileName)
configuration.shouldCompactOnLaunch = { totalBytes, usedBytes -> Bool in
    // 100 MB
    return totalBytes >= UInt(100 * 1024 * 1024) && Double(usedBytes) / Double(totalBytes) < 0.5
}
configuration.schemaVersion = DataMigrationInformationProvider().version
configuration.migrationBlock = DataMigrationManager.shared.migrate  // Migration Blocks
configuration.objectTypes = realmObjectTypes  // List all the Realm Object

try? FileManager.default.setAttributes([.protectionKey: FileProtectionType.none], ofItemAtPath: currentFolder.url.path)
for url in currentFolder {
    try? FileManager.default.setAttributes([.protectionKey: FileProtectionType.none], ofItemAtPath: url.path)
}

do {
    return try Realm(configuration: configuration)
} catch let error {
    throw RealmError.createFailed(underlying: error) // Doesn't work because it is abort() called
}

I think the migrationblock looks okay. But I'm not sure why our users db file gets corrupted randomly. I wonder is there a way to catch the error and allow us to re-create the user's database?

henry2423 avatar Aug 19 '22 18:08 henry2423

@henry2423 is the Realm version also being updated when these crashes occur? We don't have a way to catch when Core aborts at the moment.

@astigsen it is worth discussing a feature which lets Core fail gracefully as opposed to aborting on opening the database.

leemaguire avatar Aug 23 '22 14:08 leemaguire

@leemaguire Yes, we're still seeing the crash after upgrading to the latest Realm framework version. It would be great if we the Realm could fail gracefully!!

henry2423 avatar Aug 23 '22 17:08 henry2423

@henry2423 what version of Realm was the app upgrading from?

leemaguire avatar Aug 23 '22 18:08 leemaguire

@leemaguire We're upgrading from 10.28.0 to 10.28.4. But we have used the Realm framework for a long while, so I'm not sure if it is a specific issue on 10.28.0 or from the previous version.

henry2423 avatar Aug 23 '22 18:08 henry2423