realm-java: Permission denied in /src/main/cpp/io_realm_internal_SharedRealm.cpp line 101 on Huawei P8 and P8 Lite

Edit by @cmelchior See https://github.com/realm/realm-java/issues/3972#issuecomment-313675948 for the most plausible reason for this.


Goal

What do you want to achieve?

Open Realm file on Huawei P8 and Huawei P8 Lite

Expected Results

Realm should work on all devices

Actual Results

Apparently there are 2 very specific Huawei devices (Android 6.0) where Realm files cannot be opened.

There is also possibility that this only occurs in multi-process access, but it is happening in production.

io.realm.exceptions.RealmError: Unrecoverable error. Permission denied in /Users/Nabil/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.<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 x.data.repository.LongRealmRepositoryImpl.<init>(LongRealmRepositoryImpl.java:25)
	at x.data.repository.impl.tv_programs.program_info.ProgramNotificationRepositoryImpl.<init>(ProgramNotificationRepositoryImpl.java:15)
	at x.application.RestoreAfterReboot.onReceive(RestoreAfterReboot.java:38)
	at android.app.ActivityThread.handleReceiver(ActivityThread.java:2760)
	at android.app.ActivityThread.access$1800(ActivityThread.java:165)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1453)
	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)

and

io.realm.exceptions.RealmError: Unrecoverable error. Permission denied in /Users/Nabil/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.<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 x.application.CustomApplication.initializeRealm(CustomApplication.java:397)
	at x.application.CustomApplication.initialize(CustomApplication.java:229)
	at x.application.Initializer.initialize(Initializer.java:12)
	at x.presentation.view.activity.base.BaseActivity.onCreate(BaseActivity.java:261)
	at x.presentation.view.activity.DashboardActivity.onCreate(DashboardActivity.java:156)
	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)

Steps & Code to Reproduce

I do not have these devices. They are in the wild. But technically it just opens a Realm in Application.onCreate(), or in BroadcastReceiver.onReceive().

Code Sample

It really is just opening a Realm configuration. Properties:

  • No encryption
  • deleteIfMigrationNeeded()

The tricky thing here is that

1.) these devices already had permission troubles with 1.2.0 (?!) 2.) it only happens on two specific Huawei devices, but it seems to be a popular device, because it affects quite a few users… 😐 3.) the access of Realm file is multi-process (broadcast receiver + app itself)

Version of Realm and tooling

Realm version(s): 1.2.0 and 4.1.1

Realm sync feature enabled: no

Android Studio version: irrelevant

Which Android version and device:

Android: 6.0
Android Build: GRA-L09C150B390
Manufacturer: HUAWEI
Model: HUAWEI GRA-L09

and

Android: 6.0
Android Build: ALE-L21C150B588
Manufacturer: HUAWEI
Model: ALE-L21

(i think this is the same as https://github.com/realm/realm-java/issues/3972 )

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 73 (29 by maintainers)

Most upvoted comments

We are receiving the same error reports, with devices:

  • LG, LM-G710 (Android 9.0)
  • Samsung, SM-J730F (Android 9.0)
  • Samsung, SM-J610FN (Android 9.0)
  • HiSense, HS-U970 (Android 4.2.1)
  • Samsung, SM-J415FN (Android 9.0)
  • Samsung, Galaxy J5(2016) (Android 7.1.1)
  • Samsung, Galaxy Note4 (Android 6.0.1)
  • Samsung, SM-J530F (Android 8.1.0)
  • Samsung, SM-A600FN (Android 9.0)

And the list goes on… with thousands of crashes in the last 3 months (1M users, 21K daily active users)

I have not been able to read all the comments in the thread, but some error reported that the device was running low on space. I am not sure that is the cause, though, because we haven’t been able to reproduce the issue either.

Kind regards!

any update for this

@cmelchior I could not share my project with you because it is commercial project. 😭 Maybe my project enabled instant app that will trigger the crash easily. 🆘

Our understanding of the problem so far is that is an intermediate problem on Huawei devices happening either during factory reset or app upgrades. From what we can tell it is a bug in the filesystem implementation which causes our FIFO files to belong to a different process than the current app process. This is what causes PermissionDenied exception. There are some more details here: https://github.com/realm/realm-java/issues/3972#issuecomment-313675948

The FIFO files are used to coordinate notifications and access to the Realm file itself between threads and processes, so they cannot just be “disabled”.

Workarounds might be to re-create the files in a different location, but it is a big problem if the original files suddenly revert to having the correct process id. In that case, there is a pretty big chance two similar FIFO files exist, which can lead to corruption at the file level.

Alternatively, and much more heavy-handed, we throw a special type of exception that allow app developers to determine how to proceed.

Right now I’m a bit hampered in the ability to reproduce this consistently which makes testing workarounds tricky.

Versions 10.8.0, & 10.10.1 throws the following exception when I launch my app as an instant app from Android Studio, is there a way to fix this issue on Instant Apps?.

Device: Nokia 6.2 Android version: Android 10.

java.lang.RuntimeException: Permission denied 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:175)
    at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:251)
    at io.realm.BaseRealm.<init>(BaseRealm.java:141)
    at io.realm.BaseRealm.<init>(BaseRealm.java:108)
    at io.realm.Realm.<init>(Realm.java:159)
    at io.realm.Realm.createInstance(Realm.java:495)
    at io.realm.RealmCache.createInstance(RealmCache.java:494)
    at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:461)
    at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:422)
    at io.realm.Realm.getDefaultInstance(Realm.java:403)

I made a fix in Core that I believe can fix the problem. Unfortunately, it is a work-around rather than an actual fix and for existing Realm files it requires deleting all our management files which can be a bit tricky to do correctly. So I want to make sure it is well documented. We will be making a release with this probably sometime this week. The Core PR is here: https://github.com/realm/realm-core/pull/3328

Also seeing this error on Huawei mate10. ALP-L29 with Android 9.0 on app startup. So this is Huawei related and not specific to any android version. Man I really hate Huawei and their non-standard android deviations at the subsystem level.

@Zhuinden @cmelchior

It took a few releases to isolate the the Permission denied exception. But yes, I can confirm that this happens primarily on Huawei devices. Currently in this case, I don’t have any fallback - the DB is simply not available for these users (for storage).

screen shot 2018-07-31 at 9 42 19 am screen shot 2018-07-31 at 9 42 35 am screen shot 2018-07-31 at 9 44 47 am

I had no other choice but switch back to SQLite from Realm to solve this. Using getExternalCacheDir() did not solve the issue and I was not able to get the device for debugging. 😐