realm / realm-java

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

Unrecoverable error. Permission denied in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp #3972

Closed sabergeek closed 6 years ago

sabergeek commented 7 years ago

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.

Zhuinden commented 7 years ago

SNAPSHOT 2.2.2 fixes https://github.com/realm/realm-java/issues/3629 which might fix this?

sabergeek commented 7 years ago

@Zhuinden I hope so! :) When is the release version of 2.2.2 expected to be out?

Zhuinden commented 7 years ago

Personally, I'm surprised that it still isn't.

kneth commented 7 years ago

@sabergeek Can you verify that SNAPSHOT 2.2.2 works for you?

sabergeek commented 7 years ago

@kneth I certainly would, but I don't have access to those specific devices, nor emulators.

kneth commented 7 years ago

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

sabergeek commented 7 years ago

@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)?

Zhuinden commented 7 years ago

@sabergeek it has less bugs than 2.2.1, and I do not know of any new bugs that were introduced.

kneth commented 7 years ago

You can either use the snapshot or wait a day (or two) to use a proper release.

sabergeek commented 7 years ago

@kneth Then I'll wait instead, and will report back soon :)

kneth commented 7 years ago

@sabergeek We have released 2.2.2 a few hours ago :-)

sabergeek commented 7 years ago

@kneth Seems to be alright! It's over a week now and no crashes yet.

kneth commented 7 years ago

@sabergeek Cool. I'll close the issue. Don't hesitate to reopen or create new issue if you see it again.

AamirAbro commented 7 years ago

@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)

Zhuinden commented 7 years ago

@AamirAbro what directory are you trying to open the Realm in?

AamirAbro commented 7 years ago

@Zhuinden the default one.

here is how am I creating the it. Realm.init(Application.getContext()); RealmConfiguration configuration = new RealmConfiguration.Builder() .deleteRealmIfMigrationNeeded() .build();

Zhuinden commented 7 years ago

Interesting, what device is it?

2.2.2 should have fixed it as per https://github.com/realm/realm-java/issues/3629

AamirAbro commented 7 years ago

@Zhuinden Its happening mostly on HUAWEI devices. Here is the distribution of users who git this crash after realm 2.2.2 update.

screen shot 2017-01-29 at 6 05 13 pm screen shot 2017-01-29 at 6 05 21 pm screen shot 2017-01-29 at 6 05 28 pm
Zhuinden commented 7 years ago

@AamirAbro do you open Realm instance in application.onCreate(), or in Activity.onCreate()?

AamirAbro commented 7 years ago

in activity on create.

Zhuinden commented 7 years ago

@beeender

AamirAbro commented 7 years ago

any update, I have been seeing this crash alot. :(

sabergeek commented 7 years ago

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

Zhuinden commented 7 years ago

But what devices do you see this on?

sabergeek commented 7 years ago

@Zhuinden So far this was reported only on Lenovo A7010a48 - Android 6.0.

SergiLlamasGuerrero commented 7 years ago

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.

nhachicha commented 7 years ago

@beeender @kneth do we have this HUAWEI device or should we order one for tests?

beeender commented 7 years ago

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

kneth commented 7 years ago

I put in "On Hold" until @beeender has a chance to try to reproduce it.

sabergeek commented 7 years ago

@beeender I'll send it to you privately. Any email ID you can share?

kneth commented 7 years ago

@sabergeek Please send it to help@realm.io.

lkishor commented 7 years ago

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()

bmeike commented 7 years ago

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

sabergeek commented 7 years ago

@bmeike @kneth @beeender I just sent in a mail on help@realm.io with the details and a link to the APKs. Apologies for the delay! Do let me know if you need more info.

beeender commented 7 years ago

INTERNAL INFORMATION: https://secure.helpscout.net/conversation/318133134/8775/?folderId=539748

Cannot reproduce on Huawei Honor 7 :(

beeender commented 7 years ago

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.

beeender commented 7 years ago

@SergiLlamasGuerrero can you please send your apk to us (help@realm.io) so i can try to reproduce it on HUAWEI GRA-L09 ?

SergiLlamasGuerrero commented 7 years ago

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

beeender commented 7 years ago

@SergiLlamasGuerrero Still no luck to reproduce it on Huawei Honor 7 and Huawei P8 (which is almost the same device with GRA-L09) :(

SergiLlamasGuerrero commented 7 years ago

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%). captura de pantalla 2017-02-15 a las 16 13 18 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

beeender commented 7 years ago

@SergiLlamasGuerrero When the crash happens, is it the first time the app open a Realm instance?

SergiLlamasGuerrero commented 7 years ago

@beeender According to the data we have it seems that it is as you say

bmeike commented 7 years ago

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

AamirAbro commented 7 years ago

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.

SergiLlamasGuerrero commented 7 years ago

@bmeike The information is what we have seen in Crashlytics, but we have not been able to reproduce the error either.

beeender commented 7 years ago

@AamirAbro Can you share you app with us? to help@realm.io 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.

kneth commented 7 years ago

@AamirAbro Did you send us an APK which we can try?

AamirAbro commented 7 years ago

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

kneth commented 7 years ago

@AamirAbro Thanks. We'll take a look.

beeender commented 7 years ago

@AamirAbro The apk doesn't crash with our OPO, Huawei Hornor 7, Xiaomi Mi5. We will try to find more devices to try it.