Goal
Sharing a crash log (as reported by Crashlytics) on specific devices.
Expected Results
To verify if my current API usage is correct and hopefully find a resolution.
Actual Results
Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. Permission denied 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(SharedRealm.java)
at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:205)
at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:182)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:124)
at io.realm.Realm.getInstance(Realm.java:227)
at com.project.base.BaseRealm.(BaseRealm.java)
at com.project.helpers.RepoImpl.(RepoImpl.java)
at com.project.MainActivity.initialiseHelpers(MainActivity.java:272)
at com.project.MainActivity.onCreate(MainActivity.java:162)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2937)
at android.app.ActivityThread.access$1900(ActivityThread.java:174)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1403)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5752)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(NativeStart.java)
Code:
public class BaseRealm {
private RealmConfiguration config = new RealmConfiguration.Builder().build();
protected Realm mRealm = Realm.getInstance(config);
}
public class RepoImpl extends BaseRealm implements RepoInterface {
@Override
public void add(String item) {
MyPOJO data = new MyPOJO();
data.setItem(item);
data.setTimestamp(System.currentTimeMillis());
mRealm.beginTransaction();
mRealm.copyToRealmOrUpdate(data);
mRealm.commitTransaction();
}
@Override
public int getResultCount() {
return mRealm.where(MyPOJO.class).findAllSorted("timestamp", Sort.DESCENDING).size();
}
@Override
public MyPOJO getItemObjectByIndex(int index) {
try {
return mRealm.where(MyPOJO.class).findAllSorted("timestamp", Sort.DESCENDING).get(index);
} catch (Exception e) {
return null;
}
}
@Override
public void remove(int position) {
mRealm.beginTransaction();
mRealm.where(MyPOJO.class).findAllSorted("timestamp", Sort.DESCENDING).deleteFromRealm(position);
mRealm.commitTransaction();
}
@Override
public void closeRealm() {
mRealm.close();
}
@Override
public Realm getRealm() {
return mRealm;
}
@Override
public void clearRealm() {
getRealm().beginTransaction();
getRealm().deleteAll();
getRealm().commitTransaction();
}
The RepoImpl instance is being created from two separate classes and the realm instance is being closed only when onDestroy() is triggered in each of the classes. clearRealm() is currently never called.
Realm version(s): 2.2.1
Android Studio version: 2.2.3
Which Android version and device: Samsung SM-A500F (Android 6.0) and Lenovo S1a40 (Android 4.4.4)
It's seemingly working well on other devices.
SNAPSHOT 2.2.2 fixes https://github.com/realm/realm-java/issues/3629 which might fix this?
@Zhuinden I hope so! :) When is the release version of 2.2.2 expected to be out?
Personally, I'm surprised that it still isn't.
@sabergeek Can you verify that SNAPSHOT 2.2.2 works for you?
@kneth I certainly would, but I don't have access to those specific devices, nor emulators.
@sabergeek We will release a new version soon. I hope that you will have the time to upgrade your app and monitor Crashlytics to see if the crash still occurs.
@kneth I will push an update with Snapshot 2.2.2 and report back. Is there anything else I should be aware of/ expect with this snapshot (known bugs)?
@sabergeek it has less bugs than 2.2.1, and I do not know of any new bugs that were introduced.
You can either use the snapshot or wait a day (or two) to use a proper release.
@kneth Then I'll wait instead, and will report back soon :)
@sabergeek We have released 2.2.2 a few hours ago :-)
@kneth Seems to be alright! It's over a week now and no crashes yet.
@sabergeek Cool. I'll close the issue. Don't hesitate to reopen or create new issue if you see it again.
@kneth I am seeing the similar crash in crash reports on realm 2.2.2
Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. Permission denied in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 87
at io.realm.internal.SharedRealm.nativeGetSharedRealm(SourceFile)
at io.realm.internal.SharedRealm.getInstance(SourceFile:208)
at io.realm.internal.SharedRealm.getInstance(SourceFile:186)
at io.realm.RealmCache.createRealmOrGetFromCache(SourceFile:124)
at io.realm.Realm.getInstance(SourceFile:227)
@AamirAbro what directory are you trying to open the Realm in?
@Zhuinden the default one.
here is how am I creating the it.
Realm.init(Application.getContext());
RealmConfiguration configuration = new RealmConfiguration.Builder()
.deleteRealmIfMigrationNeeded()
.build();
Interesting, what device is it?
2.2.2 should have fixed it as per https://github.com/realm/realm-java/issues/3629
@Zhuinden Its happening mostly on HUAWEI devices.
Here is the distribution of users who git this crash after realm 2.2.2
update.
@AamirAbro do you open Realm instance in application.onCreate()
, or in Activity.onCreate()
?
in activity on create.
@beeender
any update, I have been seeing this crash alot. :(
@kneth @Zhuinden @AamirAbro Confirmed. I'm seeing the error again on 2.2.2 (Just found out 2.3.0 is out, does it fix this issue?) -
Unrecoverable error. Permission denied in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 87
I also noticed the line number to which the log is pointing at is different this time. The log shared originally in this thread was pointing at 92 - This time at 87. Not sure if this will be helpful.
PS - I'm unable to re-open this issue since it seems like I don't have the privileges.
But what devices do you see this on?
@Zhuinden So far this was reported only on Lenovo A7010a48 - Android 6.0.
Hi!
We also have the same problem here. In Crashlitycs we have a crash:
Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. Permission denied 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.getDefaultInstance(Realm.java:209)
By now 100% of it are reported by HUAWEI GRA-L09 and 6.0 version.
And finally we are using 2.3.0 Realm version.
There are any news already? Do you need more information?
Thank you for your work.
@beeender @kneth do we have this HUAWEI device or should we order one for tests?
@sabergeek I have a Huawei device, would you please share your apk somewhere so I can verify it on my device first? Hope I can reproduce it .
I put in "On Hold" until @beeender has a chance to try to reproduce it.
@beeender I'll send it to you privately. Any email ID you can share?
@sabergeek Please send it to [email protected].
Hi all,
I am also getting this issue:
Permission denied in /home/cc/repo/realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 87
Realm V 2.2.2
on
Lenovo S1a40
&
HTC Desire 526GPLUS dual sim
in
Activity.onCreate()
@sabergeek @lkishor We have been unable to reproduce this bug. We need your assistance! @beeender has a Huawei device. If one of you can send us an apk that will enable us to see the problem we'd be eternally grateful.
@bmeike @kneth @beeender I just sent in a mail on [email protected] with the details and a link to the APKs. Apologies for the delay! Do let me know if you need more info.
INTERNAL INFORMATION: https://secure.helpscout.net/conversation/318133134/8775/?folderId=539748
Cannot reproduce on Huawei Honor 7 :(
Some updates:
I try to reproduced this issue with devices in this issue on http://remote.testin.cn/machine/device/index , but no luck :(
https://code.google.com/p/android/issues/detail?id=8886 this Android issue seems to be related with this crash. But if that happens (context.getFilesDir()
returns null
), it should crash in SharedRealm.initialize()
when mkdir()
called first.
@SergiLlamasGuerrero can you please send your apk to us ([email protected]) so i can try to reproduce it on HUAWEI GRA-L09 ?
Thank you @beeender for your help.
Our app is this one: https://play.google.com/store/apps/details?id=com.geomobile.tiendeo&hl=es
And this is the information about this crash provided by Fabric: http://crashes.to/s/5797e3f66da
I hope this helps!
Sergi
@SergiLlamasGuerrero Still no luck to reproduce it on Huawei Honor 7 and Huawei P8 (which is almost the same device with GRA-L09) :(
I don't know if it will help but now the 84% of devices that crashed with this error are HUAWAI, and the 72% of HUAWAI that crashed are ALE-L21, followed by hi6210sft16 (16%) and then HUAWEI GRA-L09 (6%).
However, this crash is not very common (130 crashes in a week from only 22 users and the app had 253.4k active users the same week).
Hope it could help a bit.
Thank you very much again!
Sergi
@SergiLlamasGuerrero When the crash happens, is it the first time the app open a Realm instance?
@beeender According to the data we have it seems that it is as you say
@SergiLlamasGuerrero Have you been able to repro this, or are you just seeing it in your Crashlytics reports? I am running Tiendeo on a Lenovo S1a40 Android 6.0, and have not seen it crash, yet.
We are seeing from 20-40 crashes on app a which has more then 300k users per day.
94% on Android 6 and 86% on Huawei devices.
@bmeike The information is what we have seen in Crashlytics, but we have not been able to reproduce the error either.
@AamirAbro Can you share you app with us? to [email protected] if you want to share it privately. I can try my luck with a few Huawei devices i have. Also please let me know if there are any possible steps to reproduce the issue.
@AamirAbro Did you send us an APK which we can try?
@kneth sorry for delay, I have sent the build in email, @beeender You would have to login to app for this issue, it should crash as soon as you land on main screen after login. You can create an account if don't have one.
@AamirAbro Thanks. We'll take a look.
@AamirAbro The apk doesn't crash with our OPO, Huawei Hornor 7, Xiaomi Mi5. We will try to find more devices to try it.
I have this crash also reported on Huawei P8 lite and LG G3
@slezadav do you have Realm in internal storage?
we are still facing this crash. :(
@AamirAbro @slezadav Can you reproduce the crashes in your test labs? Or do you only see the crashes "in the wild"?
@kneth only in wild :(
I also got the crash.
Unrecoverable error. Permission denied in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp
Realm version: 3.2.0
Which Android version and device: HUAWEI GRA-UL10 (Android 5.0) and HUAWEI MT7-TL10 (Android 6.0)
Some updates:
I got the ZTE phone, but still no luck to reproduce the issue.
I doubt even on those phones it is not 100% reproducible :(
Anyone who have this issue reported, would you please help to check if there any other crash reported for the similar phone sets?
I found those phones have some in common that they have relatively small disk space. So maybe the error happens when it runs out of disk?
I also tried to fill up the disk of the ZTE phone, but i got a crash earlier when mkdir
called. And it seems to be difficult to full fill the disk (the system really tries hard to reserve around 30MB+ disk space).
Hello,
same issue here!
device: Huawei ALE-L21
android: 6
reproduce: In my case, this issue faced every time, after a "factory reset" of the phone, and then installing the application. After that, if you clean install the application, there is no crash.
issue:
io.realm.exceptions.RealmError: Unrecoverable error. Permission denied in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 238
at io.realm.internal.SharedRealm.nativeGetSharedRealm(Native Method)
at io.realm.internal.SharedRealm.
at io.realm.Realm.getDefaultInstance(Realm.java:273)
@alexandrosla Do you know how to reproduce the issue again after a "factory reset"? We got a ALE-L21, but no luck to reproduce it still.
@beeender the issue appears every time, when installing the application for first time (and open whatever functionality using realm), after a factory reset, on ALE-L21.
@alexandrosla what is the ROM version of you ALE-L21?
@beeender
model: ALE-L21
version number: ALE-L21C02B589
android version: 6.0
EMUI version: EMUI 4.0
kernel: 3.10.86-g7b77e01
Realm version: 3.3.2
@beeender
Also if I put this code after realm init (application):
Realm.setDefaultConfiguration(new RealmConfiguration.Builder().build());
crash log has an additional line:
io.realm.exceptions.RealmFileException: Permission denied () (/data/data/{package-name}/files/default.realm) in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 238 Kind: ACCESS_ERROR.
at io.realm.internal.SharedRealm.nativeGetSharedRealm(Native Method)
at io.realm.internal.SharedRealm.
at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:244)
at io.realm.BaseRealm.
at io.realm.BaseRealm.
at io.realm.Realm.
at io.realm.Realm.createAndValidateFromCache(Realm.java:369)
at io.realm.Realm.createInstance(Realm.java:348)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:346)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:284)
at io.realm.Realm.getDefaultInstance(Realm.java:273)
Furthermore, if I use:
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().directory(getExternalCacheDir()).build();
is working properly.
@alexandrosla
Also if I put this code after realm init (application):
Where did you put those lines? in Application.onCreate()
? This is very useful information since it might be same error with https://github.com/realm/realm-java/issues/4493#issuecomment-297277808 .
Will it also fix the issue if you put Realm.setDefaultConfiguration(new RealmConfiguration.Builder().build());
in the first activity's onCreate
?
BTW, we downloaded rom ALE-L21C02B589 and @kneth is trying to flash our ALE-L21 with it. Hope we can reproduce it to find a proper workaround. Thanks a lot for your information!
@beeender
Yes in Application.onCreate()
edit reproduce :
I just find out, that this crash appears only, when you:
realm.init(this)
at Application.OnCreate()
Realm.getDefaultInstance();
As I have understood, remaining files when you don't wipe your data, cause this issue. If you had select to wipe data along with factory reset, or haven't install the app before the reset, then application won't crash.
In the same way, I have managed to reproduce this issue, in one of realm examples (IntroExample):
E/REALM_JNI: jni: ThrowingException 5, Permission denied in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 238, .
io.realm.examples.intro E/REALM_JNI: Exception has been thrown: Unrecoverable error. Permission denied in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 238
@alexandrosla hello! I am trying to reproduce the issue by following your steps. But i have some questions about step:
perform "factory reset" without "wiping data" (don't check wipe data option)
by factory reset
you mean the factory reset in the phone setting ? I have checked all my phones, there isn't a wiping data checkbox . The only thing similar I can see is options for wiping the sd card. That is strange if the phone does a factory reset WITHOUT resetting the internal storage. Is it a debugging option on your phone? can you please take a screen shot of this part?
Also, would you please check below information when you can reproduce the problem
adb shell dumpsys package | grep -A1 <your.package.name> | grep userId
This should give you something like
userId=10074
adb shell
cd /data/data/<your.package.name>
ls -l
The output will be like:
drwxrwx--x 2 u0_a74 u0_a74 4096 2017-06-19 11:42 cache
drwxrwx--x 2 u0_a74 u0_a74 4096 2017-06-19 11:42 code_cache
drwxrwx--x 4 u0_a74 u0_a74 4096 2017-06-19 11:42 files
If the uid > 10000, it will shows as u0_axx
. eg.: 10074 shows as u0_a74
here.
My guess is, after factory reset WITHOUT wiping data on your phone, the app's dir stays with the original ownership's uid. But by installing the apk again, the uid changes to something else. Then the newly installed apk won't have permission to access the old apk's directory. I am not quite sure if this is the root case, but if it is, then it definitely a bug in the Android system. :(
@beeender Hello,
In Huawei ALE-L21, the following path:
The uid of the apk:
userId=10101
The owner uid of the app's internal storage:
need to be root
I think you are right, this should be the case. if you could reproduce it you may find something more! :)
+1, we reproduced this crashed by wiping the data of the phone.
Any tips / workarounds ?
First, thanks a lot for leading us to reproduce this annoy issue! @alexandrosla !
We can reproduce this issues with tow huawei phones, P8 Lite and Hornor 7.
I think it is definitely a bug with those Huawei device.
Huawei has a feature to do factory restore without erase all apps' internal data. But the feature has a bug which is not always reproducible that after reboot and install the apk again, the uid for a fifo file has not been set to the newly installed app's uid. It leads to a EACCES
when opening the fifo file.
First please notice that we are using mkfifo
calls to create fifo on the internal storage for internal usage -- mostly to handle inter-process/thread accessing.
I have successfully to reproduce this issue with our test case. Thus I can attach a native debugger:
The above snap shot is the stat()
call results on two files, one is a normal Realm file(stat_buf_1
), the other is a fifo file(stat_buf
). They are both on the internal storage. The snapshot was taken after factory reset, when the crash happens.
As you can see, the uid
of the normal Realm file has been changed to the newly installed apk's uid, 10093. But the uid
of the fifo file stays as the old value 10083.
And since Realm is running in the process with the new uid 10093 in this case, try to open()
the fifo file will generate an EACCES
error.
To confirm this behaviour, i created a test project which can be found on https://github.com/beeender/HuaweiFifoTest
What does it do:
before factory reset:
after factory reset:
As you can see, the normal file's uid changed to 10093 which is the new uid of the apk, but the fifo's uid stays with the old value 10094.
Then magic happens
So ... Huawei made a wonderful feature, and it works if you try hard :(
I would say it is quite difficult to workaround this from Realm side. Since the fifo's uid is different from the process Realm lives in, Realm cannot chown or delete it. The best think i can think about is try to check the fifo uid by stat()
when issue happens, then throw an special exception like InconsistentUIDDetectedException
for app to catch. The app could catch it and pop up user that he/she needs to clear the app's data storage to continue use the apk because there is a bug on the phone.
So anyone who is seeing this crash, would above solution be acceptable for you? or Do you have any better ideas to solve this?
BTW, i failed to root the device after 1 hour trying :( Although the TWRP can be flashed.
OH, right, the issue won't be reproducible with TWRP recovery, since the Huawei's restore factory without wiping internal data doesn't work with TWRP.
@beeender Very nice! :)
I think your approach would be very useful, it is much better to inform the user about a clean install, instead of a non functional/crashing app.
Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. Permission denied in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 233
at io.realm.internal.SharedRealm.nativeGetSharedRealm(SharedRealm.java)
at io.realm.internal.SharedRealm.(SharedRealm.java:192)
at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:244)
at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:208)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:298)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:284)
at io.realm.Realm.getInstance(Realm.java:293)
is this exception is the same issue here?
because the line here is 233
@beeender , @alexandrosla
I'm using io.realm:realm-gradle-plugin:3.3.1
@tamtom yes, it looks like the same issue. What kind of device did you see this crash on?
@beeender here is the list of the devices that crash,
we decided to implement your solution, is there anyway to delete all realm files without getting realm instance?
our solution is to try catch our first realm call then on catch delete app data programmatically
if (VERSION_CODES.KITKAT <= VERSION.SDK_INT) {
((ActivityManager)context.getSystemService(ACTIVITY_SERVICE))
.clearApplicationUserData(); // note: it has a return value!
} else {
// use old hacky way, which can be removed
// once minSdkVersion goes above 19 in a few years.
}
@tamtom you can use Realm.deleteRealm(RealmConfiguration)
@tamtom I don't think that will work.
When realm file created, there are some other files will be created as well, eg.:
test.realm
test.realm.management/.test.realm.xxx.cv
//...
When the problem happens, you can delete test.realm. But those .cv
files belong to another uid which you don't even have permission to delete it.
@beeender so
((ActivityManager)context.getSystemService(ACTIVITY_SERVICE))
.clearApplicationUserData();
will work? I have tested and the size of data is 0
I cant reproduce the crash because I don't have huawei device.
I am not quite sure if clearApplicationUserData
works. need to check its implementation. But if it is just deleting all the internal data files from the app's process, it won't work. Since the app process doesn't have permission for those buggy uid files.
However, you can try it with a rooted devcies. just chown
the files in the internal files
dir to some other app's uid with root permission then try to clean them by calling clearApplicationUserData
.
@beeender technically with root access you could rewrite the files to proper uid
too, no?
@Zhuinden yes, with root access you can do almost everything you want :P
@beeender so the only solution is to tell the user to go to Apps-> [App name] -> clear data?
@tamtom hey, just checked the implementation of clearApplicationUserData()
, it is actually calling into ActivityManager
to ask system to clear the data which should be just the same as user click the button in the settings.
clearApplicationUserData()
will 1. clean the app data, 2. kill the app process.
So that would be a working solution! I will try to test that when I got time someday.
@beeender I tested it and its working, I went to first realm call happen in the app and catch the exception on catch I call clearApplicationUserData()
this is the best workaround for now and the crashes went down to 0 on fabric crash reports. 馃槃
Key info from #5142
Steps & Code to Reproduce
Never reproduced this manually. Received this stacktrace in our crash reporting tool. Appears to be happening only on Lenovo A7010a48 running Android 6.0. This crash happens when Realm.getDefaultInstance() is called from the onCreate() of my MainActivity, which means the app crashed on launch. init() happens in the Application class. The app is a single process application so there is probably no way for init() to go wrong.
Version of Realm and tooling
Realm version(s): 2.3.1
Realm sync feature enabled: no
Android Studio version: 2.3.3
Which Android version and device: Lenovo A7010a48 running Android 6.0
Hello, I have the same issue in many HUAWEI devices. The stack is
io.realm.exceptions.RealmError
Unrecoverable error. Permission denied in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 101
io.realm.internal.SharedRealm.nativeGetSharedRealm(Native Method)
io.realm.internal.SharedRealm.<init>(SourceFile:194)
io.realm.internal.SharedRealm.getInstance(SourceFile:241)
io.realm.internal.SharedRealm.getInstance(SourceFile:231)
io.realm.RealmCache.b(SourceFile:317)
io.realm.RealmCache.a(SourceFile:281)
io.realm.x.l(SourceFile:331)
And I think it's not friendly to use clearApplicationUserData()
. So I use Realm.deleteRealm(configuration)
, and it seems worked well in my test. But in my root dir, I don't have .cv files, only xxx.realm, xxx.realm.lock. In my xxx.management dir, there is no .cv file, either.
BTW, I think most crash in HUAWEI device is caused by OTA.
Hi, I see same crashreports on Huawei P8, LIW-L21 and Honor 7
Realm 4.1.1
Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. Permission denied in /Users/<UserName>/Dev/realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 101
at io.realm.internal.SharedRealm.nativeGetSharedRealm(SharedRealm.java)
at io.realm.internal.SharedRealm.<init>(SharedRealm.java:172)
at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:219)
at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:209)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:319)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:282)
at io.realm.Realm.getInstance(Realm.java:353)
at ru.zzz.core.injection.modules.RealmModule.provideRealm(RealmModule.kt:100)
at ru.zzz.core.injection.modules.RealmModule_ProvideRealmFactory.get(RealmModule_ProvideRealmFactory.java:30)
at ru.zzz.core.injection.modules.RealmModule_ProvideRealmFactory.get(RealmModule_ProvideRealmFactory.java:10)
at ru.zzz.base.ui.BaseActivity.onCreate(BaseActivity.kt:107)
at ru.zzz.prelogin.view.PreloginActivity.onCreate(PreloginActivity.kt:75)
at android.app.Activity.performCreate(Activity.java:6367)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2404)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2511)
at android.app.ActivityThread.access$900(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1375)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5621)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
Close this since it is not Realm side issue. See https://github.com/realm/realm-java/issues/3972#issuecomment-313675948 for more details and potential workaround.
Guys, I have set this code,
How i'm calling realm
If the exception has Permission denied message, i will clear all data.
Android has clear data method after kit-kat, but if the version code less than 19, i have to delete the data manually.
Hi
I have a similar crash on 4.3.2 but with a sligh different name. It's same issue here ?
BTW: This realm instance was created at when Application onCrate
method is called and never close in the whole lifecycle of the app.
Not sure this is relevant or not.
Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. Permission denied in /Users/Nabil/Dev/realm/master/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 101
at io.realm.internal.OsSharedRealm.nativeGetSharedRealm(Unknown Source)
at io.realm.internal.OsSharedRealm.<init>(Unknown Source:184)
at io.realm.internal.OsSharedRealm.getInstance(Unknown Source:254)
at io.realm.internal.OsSharedRealm.getInstance(Unknown Source:244)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(Unknown Source:319)
at io.realm.RealmCache.createRealmOrGetFromCache(Unknown Source:282)
at io.realm.Realm.getDefaultInstance(Unknown Source:332)
@kuno what's relevant is the devices that you get this error in.
same here:
Caused by io.realm.exceptions.RealmError: Unrecoverable error. Permission denied in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 233
at io.realm.internal.SharedRealm.nativeGetSharedRealm(SharedRealm.java)
at io.realm.internal.SharedRealm.
at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:244)
at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:208)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:298)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:284)
On:
HUAWEI Y6II
Chromium hi6210sft39(whatever that is)
Same here
We are on 5.0.0
io.realm.exceptions.RealmError: Unrecoverable error. Permission denied in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 101
at io.realm.internal.OsSharedRealm.nativeGetSharedRealm()(SourceFile:-2)
at io.realm.internal.OsSharedRealm.<init>()(SourceFile:171)
at io.realm.internal.OsSharedRealm.getInstance()(SourceFile:241)
at io.realm.BaseRealm.<init>()(SourceFile:136)
at io.realm.BaseRealm.<init>()(SourceFile:105)
at io.realm.Realm.<init>()(SourceFile:164)
at io.realm.Realm.createInstance()(SourceFile:435)
at io.realm.RealmCache.doCreateRealmOrGetFromCache()(SourceFile:342)
at io.realm.RealmCache.createRealmOrGetFromCache()(SourceFile:282)
at io.realm.Realm.getDefaultInstance()(SourceFile:343)
Attached image shows the breakdown of devices we are facing issues with.
@izbasit wow. Where exactly do you open the Realm and in how many processes?
@Zhuinden just one process throughout the app. And we open realm everytime we want to read or write to it.
If you wanted to know where we initialize it then we do it in the Application's onCreate.
io.realm:realm-gradle-plugin:3.7.2
Also Causing this issue. please help
device :: Hauwai P8 lite @kneth
We are on 5.3.0 on seeing this crash:
Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. Permission denied in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 101
at io.realm.internal.OsSharedRealm.nativeGetSharedRealm(SourceFile)
at io.realm.internal.OsSharedRealm.(SourceFile:171)
at io.realm.internal.OsSharedRealm.getInstance(SourceFile:241)
at io.realm.internal.OsSharedRealm.getInstance(SourceFile:231)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(SourceFile:319)
at io.realm.RealmCache.createRealmOrGetFromCache(SourceFile:282)
at io.realm.Realm.getDefaultInstance(SourceFile:343)
at com.pinterest.model.realm.SearchTypeaheadLocalRealm.getSearchTypeaheadTableSize(SourceFile:128)
at com.pinterest.activity.task.activity.MainActivity$InitTypeaheadCacheTask.com.pinterest.api.model.SearchTypeaheadManager.getSearchTypeaheadTableSize(SourceFile:3055)
at com.pinterest.common.async.BackgroundTask$TaskRunnable.run(SourceFile:149)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:833)
We init Realm on app start and no queries are executed until after it is initialized. We insert on a background thread and query on the UI thread.
What other information would be helpful? Devices? OS version?
@thorbenprimke device is good, my guess goes for Huawei P8 and Huawei P8 Lite?
Ref to current open issue tracking this: https://github.com/realm/realm-java/issues/5715
We're seeing this issue on a Lenovo VIBE X3 Lite (#5715 seems specific to other devices).
Currently I'm not fond of the ActivityManager.clearApplicationUserData()
solution since I assume it will also prevent our error reporting solution (Fabric Crashyltics which doesn't appear to support flushing of reports) from notifying how often this issue is even hit since the error report will also be cleared.
For now we might just live with it given the number of devices hitting this and hope that the user will eventually re-install the app.
Is it worth attempting Realm.deleteRealm(realmConfiguration)
?
Comments in this thread seem to indicate that there would still be files left over but it wasn't clear if that will continue to pose a problem or not.
@jalexdev we had Realm.deleteRealm
and also path-based file deletions but it didn't help. :/
I do not have access to that project anymore so I do not know if the clearApplicationUserData()
thing fixed it.
@Zhuinden @cmelchior So, is there any workaround for this or the issue gets resolved in 5.8.0? This error has been reported once since I upload my application on play store which is around 2 months back. My daily active user is around 50 - 80 right now. I am initializing the Realm in Application's oncreate like this -
Realm.init(App.this);
RealmConfiguration config = new RealmConfiguration.Builder()
.encryptionKey(REALM_KEY.getBytes())
.schemaVersion(0)
.deleteRealmIfMigrationNeeded()
.build();
Realm.setDefaultConfiguration(config);
Realm.getInstance(config);
And using getDefaultInstance() wherever i need it throughout the application.
Do I need to change anything? I am not able to reproduce it.
The Device was OnePlus 3T - 8.0.0
@deathstroke007 I wish I had anything to tell you.
I actually don't even know why this issue is closed. I believe it is the most severe issue, and should be utmost priority, but it's kinda been happening for... a while now.
I believe this was closed as a duplicate of your own issues here @Zhuinden: https://github.com/realm/realm-java/issues/5715?
I'll lock this thread so we don't keep commenting on closed issues :-)
Most helpful comment
First, thanks a lot for leading us to reproduce this annoy issue! @alexandrosla !
We can reproduce this issues with tow huawei phones, P8 Lite and Hornor 7.
I think it is definitely a bug with those Huawei device.
TL;DL:
Huawei has a feature to do factory restore without erase all apps' internal data. But the feature has a bug which is not always reproducible that after reboot and install the apk again, the uid for a fifo file has not been set to the newly installed app's uid. It leads to a
EACCES
when opening the fifo file.The problem
First please notice that we are using
mkfifo
calls to create fifo on the internal storage for internal usage -- mostly to handle inter-process/thread accessing.I have successfully to reproduce this issue with our test case. Thus I can attach a native debugger:
The above snap shot is the
stat()
call results on two files, one is a normal Realm file(stat_buf_1
), the other is a fifo file(stat_buf
). They are both on the internal storage. The snapshot was taken after factory reset, when the crash happens.As you can see, the
uid
of the normal Realm file has been changed to the newly installed apk's uid, 10093. But theuid
of the fifo file stays as the old value 10083.And since Realm is running in the process with the new uid 10093 in this case, try to
open()
the fifo file will generate anEACCES
error.To confirm this behaviour, i created a test project which can be found on https://github.com/beeender/HuaweiFifoTest
What does it do:
Not surprisingly it can reproduce this behaviour by reset factory without clearing internal data.
before factory reset:

after factory reset:

As you can see, the normal file's uid changed to 10093 which is the new uid of the apk, but the fifo's uid stays with the old value 10094.
Then magic happens
So ... Huawei made a wonderful feature, and it works if you try hard :(
When would user see this crash?
Solution
I would say it is quite difficult to workaround this from Realm side. Since the fifo's uid is different from the process Realm lives in, Realm cannot chown or delete it. The best think i can think about is try to check the fifo uid by
stat()
when issue happens, then throw an special exception likeInconsistentUIDDetectedException
for app to catch. The app could catch it and pop up user that he/she needs to clear the app's data storage to continue use the apk because there is a bug on the phone.So anyone who is seeing this crash, would above solution be acceptable for you? or Do you have any better ideas to solve this?