I am receiving this crash on my production app.
I am using compactRealm whenever the app starts.
Below is my complete crash log:
Caused by io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.socialcops.collect.plus/files/collect.realm': Bad Realm file header (#1). in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 92
at io.realm.internal.SharedRealm.nativeGetSharedRealm(Unknown Source)
at io.realm.internal.SharedRealm.initialize(Unknown Source)
at io.realm.internal.SharedRealm.initialize(Unknown Source)
at io.realm.BaseRealm.beginTransaction(Unknown Source)
at io.realm.Realm.compactRealm(Unknown Source)
at com.socialcops.collect.plus.configuration.BootstrapApplication.compactRealm(Unknown Source)
at com.socialcops.collect.plus.configuration.BootstrapApplication.onCreate(Unknown Source)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:697)
Realm version(s): 2.2.0
Realm sync feature enabled: No
Android Studio version: 2.3
realm file seems to be corrupted.
Can you access the realm file?
I haven't been able to reproduce this myself. I have got this crash on crashlytics.
But the app crashes as soon as the app starts
What might be reasons for this corruption? What are the possible recovery methods if the realm file gets corrupted? @zaki50
Hey, any help would be appreciated as quickly as possible. This is a critical issue our users are facing in the production environment. Thanks!
Compacting isn't done in-place so it is required that there is enough space on the device. If there is not enough space, compacting should fail (and return false). Do you have any indications of that?
Can you share the code where you call compactRealm()
?
```public class BootstrapApplication extends MultiDexApplication {
/**
* current application instance
*/
private static Context context;
private static String TAG = BootstrapApplication.class.getSimpleName();
public static Context getContext() {
return BootstrapApplication.context;
}
@NonNull
private RealmConfiguration getRealmConfiguration() {
Realm.init(getContext());
return new RealmConfiguration.Builder().name("collect.realm").schemaVersion(12).migration(new Migration()).build();
}
/**
* initialize realm database
* and define migrate file
* for thatm
*/
private void initializeRealmDatabase() {
RealmConfiguration realmConfiguration = getRealmConfiguration();
Realm.setDefaultConfiguration(realmConfiguration);
}
/**
* on create called, when application is started
*/
@Override
public void onCreate() {
super.onCreate();
BootstrapApplication.context = getApplicationContext();
Fabric.with(this, new Crashlytics(), new CrashlyticsNdk());
initializeRealmDatabase();
compactRealm();
}
private void compactRealm() {
boolean isCompact = Realm.compactRealm(getRealmConfiguration());
LogUtils.logDebugMessage(TAG, AppConstantUtils.FUNCTION_NAME_LABEL + "compactRealm(): " + isCompact);
}
/**
* @param base initialize activity as
* multi dex application
*/
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}```
I am calling compactRealm()
as soon as the application class is created just after initialising the db
If you have any second process (android:process=":remote"
) in your AndroidManifest, then compacting can happen in multiple processes in which case they can easily corrupt the Realm file
Nope, I don't have that in my Android Manifest
@tanayagrawal How many users are affected by this? Also what kind of devices are this being triggered on? If you cannot reproduce it, it sounds like a problem on specific devices?
According to my crash reports, it is currently being faced by 20 users.
Below is a list of devices where this issue is happening :
@cmelchior what if the Compact happens before the Migration (triggered by Realm.getDefaultInstance()
)?
@cmelchior Does that make sense? ^
I guess that you are compacting before migration simply from the fact that compacting requires that no other Realm instance is open. That implies that compacting is the first thing you do.
By the way, do you store the Realm files on external storage (see #4140)?
Nope, my realm files are on the internal storage.
What happens in this case:
compactRealm()
is called@tanayagrawal If compactRealm()
doesn't return false
, I think it's a bug. Compacting requires that no other instances are open.
@tanayagrawal Did you have a chance to see if compactRealm()
returns true
prior to a crash?
I am closing the issue. If you have new information, we can always reopen.
@kneth New dev from @tanayagrawal 's team here.
It appears that compactRealm()
does not return at all when this happens. The exception is thrown before it gets to return false.
@adwaitv Thanks for the feedback. I will reopen the issue so we can prioritize it.
@tanayagrawal @adwaitv Do you access to the Realm file? Or the log? You can send it to [email protected] if you wish to share it privately.
The same issue here (not using compactRealm
)
The issue occurs only on android 4
Stacktrace:
Fatal Exception: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{/....EventActivity}: io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/[package]/files/58e6a92df29a410011f3fc97.realm': Bad Realm file header (#3). (Bad Realm file header (#3)) in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 92 Kind: ACCESS_ERROR.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2124)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2248)
at android.app.ActivityThread.access$600(ActivityThread.java:145)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5095)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/[package]/files/58e6a92df29a410011f3fc97.realm': Bad Realm file header (#3). (Bad Realm file header (#3)) in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 92
at io.realm.internal.SharedRealm.nativeGetSharedRealm(SharedRealm.java)
at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:209)
at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:186)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:124)
at io.realm.Realm.getInstance(Realm.java:227)
at .......getRealmInstance(Linkry.java:215)
at .....ActivityPresenter.(EventActivityPresenter.java:31)
at .....ActivityPresenter.newInstance(EventActivity.java:1037)
at java.lang.Class.newInstanceImpl(Class.java)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1057)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2115)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2248)
at android.app.ActivityThread.access$600(ActivityThread.java:145)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5095)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(NativeStart.java)
@atouchsimo what device, which Realm version?
device: HUAWEI P6100
realm version: 2.3.0
@atouchsimo Is it similar to http://www.phonearena.com/phones/Huawei-Ascend-G610_id9408?
@kneth i have no idea, i got the crash report on fabric
@atouchsimo We have experience a rather ugly bug in older devices - see #3651. I don't think this issue is related. I haven't seen Huawei P6100 (or G610) in the shops I typically find older devices in.
@kneth just got another report, a crash happened on OnePlus 3
with android 7.1.1
@atouchsimo What is the exception you get on OnePlus 3
? Is it:
io.realm.exceptions.RealmError: Unrecoverable error. Invalid argument in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 87
Are you using realm on the external storage?
@beeender no the same exception i got at the top,
Unable to open a realm at path '/data/data/[package]/files/58e6a92df29a410011f3fc97.realm': Bad Realm file header
internal storage
@atouchsimo Is it possible for you to reproduce it? Can you provide the source code of your app? Or just an apk? You are welcome to send it to [email protected] if you wish to share it privately.
For our users, the issue seems to be occurring on all Android versions rather uniformly whenever it does.
I can't find a way to reproduce this myself and I don't have access to the realm file either. All I have to show is that Stacktrace which comes from crashlytics. It has affected 13 users in the last 90 days.
@kneth Got the same issue on LG device (not rooted). Crash report from Fabric Crashlitycs
Basic info & Stacktrace:
1) DB on external storage
2) DB file has custom name (see in logs)
3) Without migration process
4) This crash was called once only
Date: 2017-04-23T17:52:12Z
OS Version: 5.0.2
Device: LG-D724
RAM Free: 34.3%
Disk Free: 13.7%
Fatal Exception: java.lang.RuntimeException: Unable to create application com.onebit.nimbusnote.application.App: io.realm.exceptions.RealmFileException: Unable to open a realm at path '/storage/emulated/0/Android/data/com.bvblogic.nimbusnote/NimbusNote/SciJoker/DB/NimbusNoteDB4.realm.lock': open() failed: Interrupted system call. (open("/storage/emulated/0/Android/data/com.bvblogic.nimbusnote/NimbusNote/SciJoker/DB/NimbusNoteDB4.realm.lock") failed: Interrupted system call) (/storage/emulated/0/Android/data/com.bvblogic.nimbusnote/NimbusNote/SciJoker/DB/NimbusNoteDB4.realm.lock) in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 217 Kind: ACCESS_ERROR.
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4653)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1370)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by io.realm.exceptions.RealmFileException: Unable to open a realm at path '/storage/emulated/0/Android/data/com.bvblogic.nimbusnote/NimbusNote/SciJoker/DB/NimbusNoteDB4.realm.lock': open() failed: Interrupted system call. (open("/storage/emulated/0/Android/data/com.bvblogic.nimbusnote/NimbusNote/SciJoker/DB/NimbusNoteDB4.realm.lock") failed: Interrupted system call) (/storage/emulated/0/Android/data/com.bvblogic.nimbusnote/NimbusNote/SciJoker/DB/NimbusNoteDB4.realm.lock) in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 217
at io.realm.internal.SharedRealm.nativeGetSharedRealm(SharedRealm.java)
at io.realm.internal.SharedRealm.<init>(SharedRealm.java:190)
at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:237)
at io.realm.BaseRealm.<init>(BaseRealm.java:80)
at io.realm.Realm.<init>(Realm.java:140)
at io.realm.Realm.createAndValidate(Realm.java:287)
at io.realm.Realm.createInstance(Realm.java:266)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:145)
at io.realm.Realm.getDefaultInstance(Realm.java:211)
at com.onebit.nimbusnote.application.App.realm(App.java:199)
at com.onebit.nimbusnote.material.v4.db.DBInjector.exec(DBInjector.java:13)
at com.onebit.nimbusnote.material.v4.db.repositories.FolderObjRepository.createImportantForWorlFoldersI(FolderObjRepository.java:744)
at com.onebit.nimbusnote.application.App.initializeDB(App.java:134)
at com.onebit.nimbusnote.application.App.startSetup(App.java:100)
at com.onebit.nimbusnote.application.App.onCreate(App.java:68)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4650)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1370)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
@ablack13 it seems that your problem is different. It doesn't say "Bad realm header". Check storage permissions maybe?
@adwaitv You're right. Write permissions denied. But after reboot all ok
Thanks. My issue solved
We haven't been able to reproduce this issue. Please upgrade to a recent version and see if it still persists.
We can't reproduce this issue either. We'll get back to you if the problem persists on upgrading realm.
Hey guys, I'm going to close this ticket. Please feel free to re-open it if the problem shows up again or open a new one, if we can help you with anything else
I'm having the same issue, do i need any extra configuration if i'm using realm in different library but accessing them in another library ?
I'm using clean-architecture in my project my data-layer use realm. the presentation layout configure realm, i do it in the onCreate of my application but it's still crash
Caused by: io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.example.blabla/files/default.realm': Realm file decryption failed. (Realm file decryption failed) (/data/data/com.example.blabla/files/default.realm) in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 252 Kind: ACCESS_ERROR.
If think its because the realm file from the data-layer is created without encryption and i'm setting the encryption in my presentation layer. and realm try to access the unencrypted realm file .
If think its because the realm file from the data-layer is created without encryption and i'm setting the encryption in my presentation layer. and realm try to access the unencrypted realm file .
@bitsydarel yeah, that is expected. You need to use different RealmConfiguration
with different name
if you want to use two Realms at the same time.
I also get this error from a lot of users. Just switched to use Realm (3.5.0)
io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.myapp/files/mydb.realm': Not a Realm file. (Not a Realm file) (/data/data/com.myapp/files/mydb.realm) in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 252 Kind: ACCESS_ERROR.
I'm not using encryption, never have compacted the file.
Do you ever delete the Realm file?
No, never. Could it be a problem if they reinstall the app? I do a backup of the mydb.realm file and restores it, using a BackupAgent.
That can cause trouble if the Realm you back up is open when it is backed up, backing up a Realm file created by writeCopyTo
is safer.
Ok, so in the BackupAgent, I write a copy, and the make a backup of that
and when android is restoring, I rename it to the real file?
Yep, but generally it's best if on restoration, the Realm is not open.
Android restores when it installs the app, before it's even opened the first time, so I guess that shouldn't be any problem.
Still have this issue in my production environment on Samsung SM-J730FM (android 8). Any thoughts?
Caused by io.realm.exceptions.RealmFileException
Unable to open a realm at path '/data/data/megakit.mirandakotlin/files/miranda.realm': Realm file has bad size. (Realm file has bad size) (/data/data/megakit.mirandakotlin/files/miranda.realm) in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 101
I too have the issue on Android. Reading from internal storage Downloads location
"Unable to open a realm at path '/storage/emulated/0/Download/1539961870123_0_MyFile.realm.management'. Please use a path where your app has read-write permissions."
Same issue on
Device
Brand: samsung
Model: Galaxy S8+
Version: 7.1.2
Fatal Exception: io.realm.exceptions.RealmFileException
Unable to open a realm at path '/data/data/com.drved.astrology/files/default.realm': Not a Realm file. (Not a Realm file) (/data/data/com.drved.astrology/files/default.realm) in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 252
Am getting the same crash too:
io.realm.exceptions.RealmFileException: Unable to open a realm at path '/storage/emulated/0/Android/data/com.uba.uinsta/files/data/default.realm': Realm file decryption failed.
My realm encryption key is the same yet it alsways crashes. need help on this...
Most helpful comment
Am getting the same crash too:
io.realm.exceptions.RealmFileException: Unable to open a realm at path '/storage/emulated/0/Android/data/com.uba.uinsta/files/data/default.realm': Realm file decryption failed.
My realm encryption key is the same yet it alsways crashes. need help on this...