9

------LE: We ended up removing the encryption of the database because with realm team suggestions it got worse - all we could do was to remove the database and loose all stored info. Now we encrypt in keychain only the fields we need.------

I have an app released in store and after updating their iOS version to 14+, users started to complain about info not being populated from database. Not all users with iOS 14+ have this issue, it appears randomly on some devices.

The issue goes away for awhile if they reinstall the app or after they update it to another version, but after using it for a few minutes it happens again.

My database uses encryption as documented here.

The store version of my app uses Realm 5.4.8, but I tested their last version (10.0.0) and the issue is still present.

I checked this issue but it's not the case for me, I don't have a shared app group container or a share extension.

Here's how the initialisation of realm looks like:

override init() {
    super.init()

    do {
        guard let config = getMigrationAndEncryptionConfiguration() else {
            realmConfigured = try Realm()
            return
        }
        realmConfigured = try Realm(configuration: config)
    } catch let error as NSError {
        // this is where I got the error:
        //"Encrypted interprocess sharing is currently unsupported.DB has been opened by pid: 4848. Current pid is 5806."
    }
}

func getMigrationAndEncryptionConfiguration() -> Realm.Configuration? {
    let currentSchemaVersion: UInt64 = 19
    
    if Keychain.getData(for: .realmEncryptionKey) == nil {
        var key = Data(count: 64)
        _ = key.withUnsafeMutableBytes { bytes in
            SecRandomCopyBytes(kSecRandomDefault, 64, bytes)
        }
        Keychain.save(data: key, for: .realmEncryptionKey)
    }
    
    guard let key = Keychain.getData(for: .realmEncryptionKey) else {
        return nil
    }

    let fileUrl = Realm.Configuration().fileURL!.deletingLastPathComponent()
        .appendingPathComponent("Explorer.realm")
    
    var config = Realm.Configuration(fileURL: fileUrl,
                                     encryptionKey: key,
                                     schemaVersion: currentSchemaVersion, migrationBlock: { (migration, oldVersion) in
                                        if oldVersion != currentSchemaVersion {
                                            print("we need migration!")
                                        }
    })
    
    return config
}

I had another question opened for the same issue on SO, but it was closed because I didn't have enough details. After another release of my app with more logs, I could find the error that appears at initialisation of realm:

"Encrypted interprocess sharing is currently unsupported.DB has been opened by pid: 4848. Current pid is 5806. "

This appears after the app goes to background, it gets terminated (crash or closed by the system/user) and when the users opens it again, realm fails to init.

I read all about encrypted realm not being supported in app groups or in a share extension, but I didn't implement any of that in my app, is there any other reason why this error happens?

I also removed Firebase Performance from my app because I read that this module could generate issues on realm database, but it didn't help.

I opened an issue on realm github page, but I got no answer yet.

Does anyone have any idea how to fix this or why is this happening?

Thank you.

Aura
  • 246
  • 1
  • 10

0 Answers0