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

Created on 26 Jan 2018  路  73Comments  路  Source: realm/realm-java

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 )

O-Community Reproduction-Required T-Bug-Crash

Most helpful comment

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

All 73 comments

I also see that there were similar problems with Huawei after factory reset, but it affects 267
users which means it's highly unlikely that they're all doing factory reset without wiping data. 馃槃

Now this is a question worth investigating for the app: https://github.com/realm/realm-java/issues/3972#issuecomment-311869899

We'll try to change the directory

RealmConfiguration realmConfiguration = new RealmConfiguration.Builder()
                                                .directory(getExternalCacheDir())
                                                .build();

On those Huawei devices and see if it helps...

Thanks for digging through our own issues @Zhuinden 馃槃 , let us know if it makes a difference.

For others, there are also more context here: https://github.com/realm/realm-java/issues/3972#issuecomment-313675948

My guess is that there are other situations than factory reset that might cause the uid to change, but exactly what is hard to tell.

The tricky thing is that it ONLY happens in Huawei P8 and Huawei P8 Lite.

Based on the logs however, I think it is most prominent when you actually try to... Reboot the phone, and access Realm in a broadcast receiver that receives BOOT_COMPLETED.

I'm not sure when the next update roll out will happen though, so checking will be tricky. I kinda wish I had this device physically

Hey @Zhuinden

Is there any update on this issue?

I am facing the same crash on line 101 of io_realm_internal_SharedRealm.cpp.

Following are the details about the device
screen shot 2018-04-05 at 3 41 38 pm

@rahulrvp I no longer work there but my ex-workmate is trying to workaround this issue today, I don't know if he's succeeded yet.

My guess is that we should open Realm into getExternalCacheDir() on the two HUAWEI devices, his guess is that he should just clear user data for the app if the error comes up.

I also think that this is related to multi-process Realm access on Huawei devices, MAYBE related to the lock file not being released right, OR the system not allowing the creation of pipe files in /data/data/package (which would be a real bummer)

I wish I had the device myself 馃槃 but as I don't, I only have guesses

@Zhuinden thanks for the quick reply.

This one is not a Huawei device. And even I don't have this device with me. This is a crash report came from one of the users who uses this app. 馃槃

Anyways, I will do the workaround you've suggested and will see if that helps.

Thanks!

I'd only use the getExternalCacheDir() on the specific device type where the error occurs, though.

I'd prefer to store my Realm in /data/data if possible 馃槃

This really is problematic though because the Huawei P8 is quite popular in this area.

I think that multi-process access might be related, but I'm not entirely sure. I don't have the test phone. :|

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. :|

@Zhuinden thank you so much for spending your time trying to help me out. I really appreciate that! :)

What sucks is that I never got the phone and also never figured it out.

I really do think it has something to do with the multiprocess access that happens on booting the phone and the broadcast receiver runs.. But I have no idea what really happens.

It's strange to me that Realm gets messages from the OS that aren't very descriptive. Permission denied to do what, exactly?

In the end, this affected 1% of users and that's kind of a lot. We added the workaround "delete the data of the app if this happens" but I'm super uneasy about having to do that.

....I shoulda just bought the damn phone.

It could be an SELinux permission policy violation which results in a Permission denied, if it's the case usually you'll see logcat outputting the violation before denying the access

Example:

type=1400 audit(0.0:315): avc: denied { create } for name="access_control.new_commit.cv" scontext=u:r:system_app:s0 tcontext=u:object_r:system_app_data_file:s0 tclass=fifo_file permissive=0

https://github.com/realm/realm-java/issues/4630

I really need to buy this device at some point :smile:

But as much as I hate to say it, I think it is Realm-Core responsibility to have a workaround for when they cannot create pipe file. I think this permission issue could have been there since 0.89.0 with the introduction of named pipes, but might emerge primarily in multi-process access on some devices, or possible concurrent access on initialization.

I wonder if making getInstance() method call synchronized would have solved my issue. My ex-coworker went with the "delete everything" approach but I'm honestly not too fond of it. But that is still better than the app not starting.

One day, we should clearly buy a Huawei P8 Lite, create a multi-process sample, then figure out how beeender used to debug this sort of thing.

https://github.com/realm/realm-java/issues/3972#issuecomment-376259546 <-- this doesn't sound particularly healthy, either. I wonder if it is the same cause.

image

Are you sure the error is for Huawei P8 Lite? I see more devices in my list

For me it was on Huawei P8 and Huawei P8 Lite. Didn't happen on other devices.

I do not work there anymore though (for other reasons ofc) so my ex-co-worker attempted to add the "app clear data" workaround, I no longer have access to see if it helped either.

@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

See https://github.com/realm/realm-java/issues/3972 for more of this issue occurring.

any update ??

any updates??

Hello!

I managed to reproduce the error:

  1. Installed the app
  2. Made factory reset, but did not delete user data
  3. After factory reset and initial "welcome" setup I installed the app again - and got the error

Device: Huawei P8 and android 6.0

@roooomi Is that 100% repeatable?

Hi, @bmunkholm
Yes, it looks 100% repeatable on 2 devices (Huawei P8 and Huawei P8 lite) both with android 6.0. I tried to reproduce it also on huawei P9 lite with android 6.0 and it was not repeatable.

With each device I tried 3 times, 100% repeatable on Huawei P8 and P8 lite:

  1. Installed the app
  2. Made factory reset, but did not delete user data
  3. After factory reset and initial "welcome" setup I installed the app again - and got the error

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.

Same here, seems to be an Huawei Issue.
Any news from realm guys?

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(OsSharedRealm.java) at io.realm.internal.OsSharedRealm.<init>(OsSharedRealm.java:171) at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:241) at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:231) at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:319) at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:282) at io.realm.Realm.getDefaultInstance(Realm.java:343)

Hi, @bmunkholm
Yes, it looks 100% repeatable on 2 devices (Huawei P8 and Huawei P8 lite) both with android 6.0. I tried to reproduce it also on huawei P9 lite with android 6.0 and it was not repeatable.

With each device I tried 3 times, 100% repeatable on Huawei P8 and P8 lite:

  1. Installed the app
  2. Made factory reset, but did not delete user data
  3. After factory reset and initial "welcome" setup I installed the app again - and got the error

I cannot reproduce this issue with those steps.

Did you do the factory reset from the settings or with the recovery mode?

@appschris
The steps are as follows:

  • Installed the app
  • Made factory reset, but did not delete user data (this is from the app settings. You have to uncheck "delete user data")
  • After factory reset and initial "welcome" setup I installed the app again - and got the error

@roooomi wasnt able to reproduce it with a HUAWEI P Smart.

But i can see some HUAWEI Crashes with a P20

@appschris Hi!
I have tested this issue also with P10 (8.0) and P10+ (7.0) and P Smart (2017, 8.0) - The issue is not reproducible on any of those devices.

The only devices I know that are reproducible are: (Huawei P8 and Huawei P8 lite) and also P20 (actual end user report to us)

FWIW, I'm seeing these type of crashes increase in my crash reporting, they're mostly coming from Samsung Galaxy S9. Maybe it's not just Huawei

I think that is not the only problem with Huawei.
Sony and FUJITSU also encountered the same problem.
I am using realm-gradle-plugin: 5.9.0
However, the number of users subject to this problem is small.

2019-02-07 11 06 40

Any ways to reproduce it? @roooomi麓s way didnt work for me

Any workaround to fix it?
Fix mentioned here is not working.

Hi, any update on this? Been receiving crash report as well. Issue happens on
HUAWEI Mate 10, OS = 9

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 217

image

Considering this bug was first detected more than two years ago, there are three possible options:

1.) you should also be posting these reports in https://github.com/realm/realm-core/issues/3204 so that 1% instability rate is taken seriously (considering this bug affects about 1% of all users - with a crash on app start-up with no real way of resolving it - which with a sufficiently large userbase is actually a LOT of users)

2.) raid Realm HQ and make them implement a fallback mechanism (for example, don't use pipe files if the system doesn't allow creating them)

3.) use SQLite because it works on huawei devices too

I actually started looking into this bug. Unfortunately, there doesn't seem to be much we can do on our side as the problem is Huawei not handling fifo files correctly in some cases.

Right now it isn't clear what the best work-around is. I suspect it is us trying creating new fifo files in a different location, but I'm still working out the implications of doing that, i.e. what happens when the old fifos suddenly becomes accessible again.

I actually started looking into this bug. Unfortunately, there doesn't seem to be much we can do on our side as the problem is Huawei not handling fifo files correctly in some cases.

I have this nagging feeling that the answer lies in some sort of Core workaround when it doesn't get permission to do... well, what it wants to do.

AFAIK this came in with 0.89.0 pipe files for cross-process notification handling. I would think not having cross-process notification or cross-process locking as an opt-in would be better than outright crashing on start-up.

Yes, the interprocess support is what resulted in the current implementation. I'm not 100% sure if we can disable that easily though, but it is an interesting idea (coupled with some required config parameter so you specifically opt out of it).

We need to first confirm the following so we can at the the very least narrow it down somewhat.

1) Is this a temp ram state error caused by dangling i/o stuff in Huawei phones? Does this crash disappear once the device is restarted?

2) Some of the users here reported unreliable results that triggers after app data is not cleaned but phone is reset. Can we confirm that if realm app data is cleared BEFORE reset, the issue doesn't happen?

Even though I got a Mate10 crash on this exact issue, I was not able to reproduce this on my own Mate10 device.

A possible workaround for this at the java layer is to detect any type of unrecoverable errors in db init and manually remove all realm files and retry with perhaps new db directory.

My guess is Huawei hacked fs subsystem and forgot to free some dangling persistent file nodes that are no longer valid. Removing the app data files or db parent folder when encountered this errror would generate new file nodes and avoid any prevous bad states.

A possible workaround for this at the java layer is to detect any type of unrecoverable errors in db init and manually remove all realm files

I don't think that was sufficient for us, unfortunately. We already had a "delete all Realm related files" workaround implemented and this error still existed.

Although I do wonder if we really did delete ALL auxillary files.... It was too long ago, I cannot verify it anymore.

Maybe a new db directory could work. Not sure.

Is the error recoverable at all? Can they restart the app and hope it works? Do they need to "Clear user data/uninstall" app? Or does it crash all the time. I don't have access to a device to test this out.

Is the error recoverable at all? Can they restart the app and hope it works? Do they need to "Clear user data/uninstall" app? Or does it crash all the time. I don't have access to a device to test this out.

I also have this error coming up in my Crashlytics, but the ratio of crashes to users seem to be 1:1, which indicates that a user trying to open the app again after the crash gets it to work. I would be very surprised if all users just gave up after the first crash. Does this seem to correspond to what others are seeing in their logs?

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.

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(OsSharedRealm.java)
at io.realm.internal.OsSharedRealm.(OsSharedRealm.java:171)
at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:241)
at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:231)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:318)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:284)
at io.realm.Realm.getDefaultInstance(Realm.java:407)
at com.chope.gui.realm.ChopeRealmHelper.getRealmInstance(ChopeRealmHelper.java:71)
at com.chope.gui.realm.ChopeRealmHelper$2.onOpenInputStreamTaskCompleted(ChopeRealmHelper.java:178)
at com.chope.gui.realm.OpenStreamTask.onPostExecute(OpenStreamTask.java:72)
at com.chope.gui.realm.OpenStreamTask.onPostExecute(OpenStreamTask.java:25)
at android.os.AsyncTask.finish(AsyncTask.java:727)
at android.os.AsyncTask.access$600(AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:744)
at android.os.Handler.dispatchMessage(Handler.java:109)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:7470)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)

image

image

I have read all issue about this problem . our team has decide use SQLite instead.

We have the same errors.
Only Android 6.0
Devices:
HUAWEY Y6II
HUAWEY GR3 2017
LG K4/K7 (2017)

How to fix the bug?

Still no updates?

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!

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

Any update?

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

A fix (we believe) has been released in Realm Java 5.15.0. However, depending on your situation it might require a little extra work. Realm files created before 5.15.0 will not automatically work. See https://realm.io/docs/java/latest/#huawei-permission-denied for more details.

still crashed on Realm Java 5.15.1.

Fatal Exception: io.realm.exceptions.RealmError
Unrecoverable error. Permission denied in /Users/cm/Realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 101
io.realm.internal.OsSharedRealm.nativeGetSharedRealm (OsSharedRealm.java)
io.realm.internal.OsSharedRealm.<init> (OsSharedRealm.java:171)
io.realm.internal.OsSharedRealm.<init> (OsSharedRealm.java:171)
io.realm.internal.OsSharedRealm.getInstance (OsSharedRealm.java:241)
io.realm.BaseRealm.<init> (BaseRealm.java:136)
io.realm.BaseRealm.<init> (BaseRealm.java:136)
io.realm.BaseRealm.<init> (BaseRealm.java:103)
io.realm.BaseRealm.<init> (BaseRealm.java:103)
io.realm.BaseRealm.<init> (BaseRealm.java:103)
io.realm.Realm.<init> (Realm.java:163)
io.realm.Realm.createInstance (Realm.java:499)
io.realm.RealmCache.doCreateRealmOrGetFromCache (RealmCache.java:355)
io.realm.RealmCache.createRealmOrGetFromCache (RealmCache.java:285)
io.realm.Realm.getDefaultInstance (Realm.java:407)

image
image

Did you rename the Realm file, or clear the previous user data?

@Zhuinden I've followed the document to clear previous user data like below:

try {
        Realm.getDefaultInstance();
      } catch (RealmError e) {
        EventModule.log(this,"realm_exception", "msg", e.getLocalizedMessage());
        if (e.getMessage().contains("Permission denied")) {
          Realm.deleteRealm(Realm.getDefaultConfiguration());
        } else {
          throw e;
        }
      }

If you have absolutely nothing to lose on client side, you can try

} catch(RealmError e) {
    if(e.getMessage().contains("Permission denied")) {
        ((ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE)).clearApplicationUserData();
    }
}

It should not get permission denied exceptions after that.

I don't want to clear all user data. Why doesn't Realm.deleteRealm(Realm.getDefaultConfiguration()) work?

@hzy00 Depending on exactly what is wrong with the file permissions, calling Realm.deleteRealm() might fail since it also attempts to delete the lock files that have the wrong permissions.

In those cases deleting the entire user, data dir might work (or it might not). What should always work is re-creating the Realm with a different file name.

@Zhuinden I also tried the code below to remove all user data but the crash still occur.

} catch(RealmError e) { if(e.getMessage().contains("Permission denied")) { ((ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE)).clearApplicationUserData(); } }

It doesn't work 馃啒馃槶

@wooyukit what do you mean it doesn't work, even with latest Realm version, and retrying after this clear app data, it STILL doesn't work? 馃 Does it give any exceptions or something?

@Zhuinden Yes, I upgraded to 6.0.2. After clear app data, it still doesn't work. The exception message is same as this issue title.馃ズ

@wooyukit Is it something you can reproduce or are you only seeing it in production?

We have same problem at different devices.
We are using io.realm:realm-android-library:6.0.1@aar

Screenshot 2019-12-04 at 11 30 22 AM

Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. Permission denied in /Users/cm/Realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 101
at io.realm.internal.OsSharedRealm.nativeGetSharedRealm(OsSharedRealm.java)
at io.realm.internal.OsSharedRealm. + 171(OsSharedRealm.java:171)
at io.realm.internal.OsSharedRealm.getInstance + 241(OsSharedRealm.java:241)
at io.realm.internal.OsSharedRealm.getInstance + 231(OsSharedRealm.java:231)
at io.realm.RealmCache.doCreateRealmOrGetFromCache + 332(RealmCache.java:332)
at io.realm.RealmCache.createRealmOrGetFromCache + 285(RealmCache.java:285)
at io.realm.Realm.getDefaultInstance + 407(Realm.java:407)
...

@3c133ps3d Most of the crashes seem to be on Samsung which indicates a different problem, even though the exception message is the same. What kind of Samsung devides are affected?

@cmelchior I am using One plus 7 pro馃摫

@wooyukit If you can reproduce it locally, is it a project you can share? Privately is fine as well. In that case, you can send it to christian.[email protected]

@cmelchior I think its because we have a lot users with Samsung devices.

Actually there are different kinds of errors:
Unrecoverable error. write() failed: No space left on device,
Unrecoverable error. Too many open files.

Its not library's problem, sorry for disturbing :blush:

@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. 馃啒

@cmelchior the issue still occurs in "io.realm:realm-gradle-plugin:6.0.0" with Huawei P8 Lite.
Logs:
Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. Permission denied in /Users/cm/Realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 101
at io.realm.internal.OsSharedRealm.nativeGetSharedRealm(OsSharedRealm.java)
at io.realm.internal.OsSharedRealm.(OsSharedRealm.java:171)
at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:241)
at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:231)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:332)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:285)
at io.realm.Realm.getDefaultInstance(Realm.java:407)

We noticed that the crash also occurs in other devices like the Xiaomi Mi9 but it is never logged in the crashlytics tool.

Guys any solution for this issue? Or I have to fall back on SQLite?

@mianaliasjad what is your Realm version and is your app multi-process

no my app is not multiprocess.
using:
classpath "io.realm:realm-gradle-plugin:5.10.0"

https://github.com/realm/realm-java/blob/master/CHANGELOG.md#51502019-09-05

Says 5.15.0 is the one where this was supposedly fixed for newly created Realm files.

Was this page helpful?
0 / 5 - 0 ratings