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

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

This comment has been minimized.

Copy link
Contributor

commented Jan 1, 2017

SNAPSHOT 2.2.2 fixes #3629 which might fix this?

@sabergeek

This comment has been minimized.

Copy link
Author

commented Jan 2, 2017

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

@Zhuinden

This comment has been minimized.

Copy link
Contributor

commented Jan 2, 2017

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

@kneth

This comment has been minimized.

Copy link
Contributor

commented Jan 3, 2017

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

@sabergeek

This comment has been minimized.

Copy link
Author

commented Jan 3, 2017

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

@kneth

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Author

commented Jan 4, 2017

@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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Jan 4, 2017

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

@sabergeek

This comment has been minimized.

Copy link
Author

commented Jan 4, 2017

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

@kneth

This comment has been minimized.

Copy link
Contributor

commented Jan 5, 2017

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

@sabergeek

This comment has been minimized.

Copy link
Author

commented Jan 17, 2017

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

@kneth

This comment has been minimized.

Copy link
Contributor

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 Jan 17, 2017

@AamirAbro

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Jan 29, 2017

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

@AamirAbro

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Jan 29, 2017

Interesting, what device is it?

2.2.2 should have fixed it as per #3629

@AamirAbro

This comment has been minimized.

Copy link

commented Jan 29, 2017

@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

This comment has been minimized.

Copy link
Contributor

commented Jan 29, 2017

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

@beeender

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link

commented Nov 28, 2017

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2017

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

@beeender beeender closed this Dec 14, 2017

@hmedat

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Jan 27, 2018

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

@FranPR9

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Mar 26, 2018

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

@izBasit

This comment has been minimized.

Copy link

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.

@nancoding

This comment has been minimized.

Copy link

commented Apr 16, 2018

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

@thorbenprimke

This comment has been minimized.

Copy link

commented Jun 29, 2018

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

This comment has been minimized.

Copy link
Contributor

commented Jun 29, 2018

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

@cmelchior

This comment has been minimized.

Copy link
Contributor

commented Jun 29, 2018

Ref to current open issue tracking this: #5715

@jalexdev

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2018

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

@deathstroke007

This comment has been minimized.

Copy link

commented Nov 30, 2018

@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

This comment has been minimized.

Copy link
Contributor

commented Nov 30, 2018

@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

This comment has been minimized.

Copy link
Contributor

commented Dec 3, 2018

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
You can’t perform that action at this time.