realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.45k stars 1.75k forks source link

Encrypted interprocess sharing is currently unsupported.DB has been opened by pid #7788

Closed Kolyall closed 1 year ago

Kolyall commented 1 year ago

How frequently does the bug occur?

Sometimes

Description

Can't compact Realm DB:

java.lang.RuntimeException: Unable to create application com.example.TheApplication: java.lang.RuntimeException: /data/user/0/com.example.dev/files/db_example.realm: Encrypted interprocess sharing is currently unsupported.DB has been opened by pid: 12587. Current pid is 13405. in /tmp/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 107
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5876)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.RuntimeException: /data/user/0/com.example.dev/files/db_example.realm: Encrypted interprocess sharing is currently unsupported.DB has been opened by pid: 12587. Current pid is 13405. in /tmp/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 107
at io.realm.internal.OsSharedRealm.nativeGetSharedRealm(Native Method)
at io.realm.internal.OsSharedRealm.<init>(OsSharedRealm.java:174)
at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:259)
at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:247)
at io.realm.BaseRealm.compactRealm(BaseRealm.java:814)
at io.realm.Realm.compactRealm(Realm.java:1954)

When I need to call compactRealm method?

Stacktrace & log output

No response

Can you reproduce the bug?

Sometimes

Reproduction Steps

No response

Version

10.13.0

What Atlas App Services are you using?

Local Database only

Are you using encryption?

Yes

Platform OS and version(s)

Android

Build environment

Android Studio version: Android Studio Electric Eel | 2022.1.1 Patch 2 Build #AI-221.6008.13.2211.9619390, built on February 17, 2023 Runtime version: 11.0.15+0-b2043.56-8887301 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Linux 5.4.0-144-generic GC: G1 Young Generation, G1 Old Generation Memory: 4096M Cores: 12 Registry: external.system.auto.import.disabled=true debugger.watches.in.variables=false ide.text.editor.with.preview.show.floating.toolbar=false ide.instant.shutdown=false

Non-Bundled Plugins: idea.plugin.protoeditor (221.6095) com.intellij.marketplace (221.6008.18) com.intellij.javafx (1.0.4) co.anbora.labs.kse (1.2.2) JUnit4-Parallel-Runner (1.5) com.atlassian.bitbucket.references (2022.1.223) com.thoughtworks.gauge (221.6008.13) com.developerphil.adbidea (1.6.8)

Current Desktop: ubuntu:GNOME

Android Build Tools version: 7.4.2 Gradle version: https://services.gradle.org/distributions/gradle-7.5-bin.zip

cmelchior commented 1 year ago

This error doesn't happen due to use of compact, but because multiple processes are accessing the same Realm.

Even if you entire app is only use one process, we have unfortunately seen that during app upgrades some variants of Android actually have two versions of the app running at the same time, which Realm will detect as this error.

We are currently in the process of adding support for this in https://github.com/realm/realm-core/pull/6304, but until that is complete the only work-around is to try to defer opening the Realm a little bit, i.e. opening the Realm in Application.onCreate has a higher chance of triggering this.