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 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 Zhuinden commented Jan 1, 2017

SNAPSHOT 2.2.2 fixes #3629 which might fix this?

Loading

@sabergeek
Copy link
Author

@sabergeek sabergeek commented Jan 2, 2017

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

Loading

@Zhuinden
Copy link
Contributor

@Zhuinden Zhuinden commented Jan 2, 2017

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

Loading

@kneth
Copy link
Member

@kneth kneth commented Jan 3, 2017

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

Loading

@sabergeek
Copy link
Author

@sabergeek sabergeek commented Jan 3, 2017

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

Loading

@kneth
Copy link
Member

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

Loading

@sabergeek
Copy link
Author

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

Loading

@Zhuinden
Copy link
Contributor

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

Loading

@kneth
Copy link
Member

@kneth kneth commented Jan 4, 2017

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

Loading

@sabergeek
Copy link
Author

@sabergeek sabergeek commented Jan 4, 2017

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

Loading

@kneth
Copy link
Member

@kneth kneth commented Jan 5, 2017

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

Loading

@sabergeek
Copy link
Author

@sabergeek sabergeek commented Jan 17, 2017

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

Loading

@kneth
Copy link
Member

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

Loading

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

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

Loading

@Zhuinden
Copy link
Contributor

@Zhuinden Zhuinden commented Jan 29, 2017

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

Loading

@AamirAbro
Copy link

@AamirAbro 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();

Loading

@Zhuinden
Copy link
Contributor

@Zhuinden Zhuinden commented Jan 29, 2017

Interesting, what device is it?

2.2.2 should have fixed it as per #3629

Loading

@AamirAbro
Copy link

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

Loading

@Zhuinden
Copy link
Contributor

@Zhuinden Zhuinden commented Jan 29, 2017

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

Loading

@beeender
Copy link
Contributor

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

Loading

@tamtom
Copy link

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

Loading

@beeender
Copy link
Contributor

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

Loading

@cfryan1990
Copy link

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

Loading

@cvoronin
Copy link

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

Loading

@beeender
Copy link
Contributor

@beeender beeender commented Dec 14, 2017

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

Loading

@beeender beeender closed this Dec 14, 2017
@hmedat
Copy link

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

Loading

@kuno
Copy link

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

Loading

@Zhuinden
Copy link
Contributor

@Zhuinden Zhuinden commented Jan 27, 2018

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

Loading

@FranPR9
Copy link

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

Loading

@izBasit
Copy link

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

Loading

@Zhuinden
Copy link
Contributor

@Zhuinden Zhuinden commented Mar 26, 2018

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

Loading

@izBasit
Copy link

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

Loading

@shubham-soni9
Copy link

@shubham-soni9 shubham-soni9 commented Apr 16, 2018

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

Loading

@thorbenprimke
Copy link

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

Loading

@Zhuinden
Copy link
Contributor

@Zhuinden Zhuinden commented Jun 29, 2018

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

Loading

@cmelchior
Copy link
Contributor

@cmelchior cmelchior commented Jun 29, 2018

Ref to current open issue tracking this: #5715

Loading

@jalexdev
Copy link

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

Loading

@Zhuinden
Copy link
Contributor

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

Loading

@i-m-aman
Copy link

@i-m-aman i-m-aman 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

Loading

@Zhuinden
Copy link
Contributor

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

Loading

@bmunkholm
Copy link
Contributor

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

Loading

@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
Linked pull requests

Successfully merging a pull request may close this issue.

None yet