Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sabergeek opened this issue Jan 1, 2017 · 104 comments

Comments

@sabergeek
Copy link

sabergeek commented Jan 1, 2017

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
Copy link
Contributor

Zhuinden commented Jan 1, 2017

SNAPSHOT 2.2.2 fixes #3629 which might fix this?

@sabergeek
Copy link
Author

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

@Zhuinden
Copy link
Contributor

Zhuinden commented Jan 2, 2017

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

@kneth
Copy link
Contributor

kneth commented Jan 3, 2017

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

@sabergeek
Copy link
Author

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

@kneth
Copy link
Contributor

kneth commented Jan 4, 2017

@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
Copy link
Author

@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
Copy link
Contributor

Zhuinden commented Jan 4, 2017

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

@kneth
Copy link
Contributor

kneth commented Jan 4, 2017

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

@sabergeek
Copy link
Author

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

@kneth
Copy link
Contributor

kneth commented Jan 5, 2017

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

@sabergeek
Copy link
Author

sabergeek commented Jan 17, 2017

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

@kneth
Copy link
Contributor

kneth commented Jan 17, 2017

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

@kneth kneth closed this as completed Jan 17, 2017
@AamirAbro
Copy link

AamirAbro commented Jan 29, 2017

@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
Copy link
Contributor

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

@AamirAbro
Copy link

AamirAbro commented Jan 29, 2017

@Zhuinden the default one.

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

@Zhuinden
Copy link
Contributor

Interesting, what device is it?

2.2.2 should have fixed it as per #3629

@AamirAbro
Copy link

@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
Copy link
Contributor

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

@beeender
Copy link
Contributor

beeender commented Jul 13, 2017

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

@tamtom
Copy link

tamtom commented Jul 17, 2017

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

@beeender
Copy link
Contributor

beeender commented Aug 24, 2017

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

@cfryan1990
Copy link

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.

@cvoronin
Copy link

cvoronin commented Dec 6, 2017

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)

@beeender
Copy link
Contributor

Close this since it is not Realm side issue. See #3972 (comment) for more details and potential workaround.

@hmedat
Copy link

hmedat commented Dec 20, 2017

Guys, I have set this code,

How i'm calling realm
screen shot 2017-12-20 at 3 04 48 pm

If the exception has Permission denied message, i will clear all data.
screen shot 2017-12-20 at 2 59 25 pm

Android has clear data method after kit-kat, but if the version code less than 19, i have to delete the data manually.
screen shot 2017-12-20 at 3 04 13 pm

@kuno
Copy link

kuno commented Jan 27, 2018

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)

@Zhuinden
Copy link
Contributor

@kuno what's relevant is the devices that you get this error in.

@FranPR9
Copy link

FranPR9 commented Mar 13, 2018

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

On:
HUAWEI Y6II
Chromium hi6210sft39(whatever that is)

@izBasit
Copy link

izBasit commented Mar 26, 2018

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.
screen shot 2018-03-26 at 22 07 07

@Zhuinden
Copy link
Contributor

@izBasit wow. Where exactly do you open the Realm and in how many processes?

@izBasit
Copy link

izBasit commented Mar 28, 2018

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

@shubham-soni9
Copy link

io.realm:realm-gradle-plugin:3.7.2
Also Causing this issue. please help
device :: Hauwai P8 lite @kneth

@thorbenprimke
Copy link

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?

@Zhuinden
Copy link
Contributor

Zhuinden commented Jun 29, 2018

@thorbenprimke device is good, my guess goes for Huawei P8 and Huawei P8 Lite?

@cmelchior
Copy link
Contributor

Ref to current open issue tracking this: #5715

@jalexdev
Copy link

jalexdev commented Aug 23, 2018

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.

@Zhuinden
Copy link
Contributor

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

@i-m-aman
Copy link

@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

@Zhuinden
Copy link
Contributor

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

@bmunkholm
Copy link
Contributor

I believe this was closed as a duplicate of your own issues here @Zhuinden: #5715?

I'll lock this thread so we don't keep commenting on closed issues :-)

@realm realm locked as resolved and limited conversation to collaborators Dec 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests