realm / realm-java

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

RealmFileException: Realm file is currently open in another process which cannot share access with this process. #7144

Closed OleksiiVoice closed 3 years ago

OleksiiVoice commented 4 years ago

Goal

Get default realm instance

Actual Results

Application crashes

Fatal Exception: io.realm.exceptions.RealmFileException: Realm file is currently open in another process which cannot share access with this process. All processes sharing a single file must be the same architecture. (Incompatible lock file. Shared info version doesn't match, 771 10.) (/data/data/<package_name>/files/default.realm) in /Users/jasonflax/Development/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.BaseRealm.<init>(BaseRealm.java:136)
       at io.realm.BaseRealm.<init>(BaseRealm.java:103)
       at io.realm.Realm.<init>(Realm.java:163)
       at io.realm.Realm.createInstance(Realm.java:499)
       at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:355)
       at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:285)
       at io.realm.Realm.getDefaultInstance(Realm.java:407)

Steps & Code to Reproduce

Unfortunately not able to reproduce the crash locally, but get recurring crash-reports on Crashlytics. Crash occurs in different places in the code while calling Realm.getDefaultInstance()

Version of Realm and tooling

Realm version(s): 5.14.0

Realm Sync feature enabled: No

Android Studio version: 4.0.1

Android Build Tools version: 30.0.0

Gradle version/Gradle plugin: 6.1.1/4.0.0

Which Android version and device(s):

edualonso commented 4 years ago

Hi @AlexeiVoice. It is going to be nearly impossible for us to figure out what the matter with this problem is given that you ruled out automatic backups in https://github.com/realm/realm-java/issues/7102#issuecomment-703557824. Another explanation could be those users have installed a third-party backup application that copies things across devices. If that is the case, it could also cause this crash when your app is opened from a device which has a different architecture. In any case, we cannot really do much until we find a way to consistently reproduce this issue. Please let us know if you find it.

OleksiiVoice commented 4 years ago

Hi @edualonso. I see, yeah, I understand. We've added some additional logs to Crashlytics reports all over the app. According to those it looks like the issue occurs while the app is in use by a user. I haven't used any third-party backup applications, so I'm not sure if ti's possible for them to perform any kind of synchronization where other application's files are changed (sort of like cloud-storage sync where it maintains same version of file across multiple devices). I guess it's also a possibility, but doesn't sound too realistic to me. Another thing I was suspicious about is WorkManager's Workers might be running in separate process, but as I understand Realm does already support multi-process access and according to this comment Workers always execute in main process anyway

cmelchior commented 4 years ago

The problem is that it might not be your app at all, e.g. if the device is rooted and running a custom from or they are using some other 3rd party tool not part of your app.

One indication of this could be if you see what operating system they run. If many of them are using custom roms, that could point in that direction.

OleksiiVoice commented 4 years ago

Thanks for the quick response. If we can trust Firebase Crashlytics, none of the devices were rooted. I'll also add some OS-version logs to try and detect custom roms, just to be sure.

rorbech commented 4 years ago

@AlexeiVoice Maybe consider to track the installer through getInstallerPackageName to see if the app is restored in unexpected ways.

rorbech commented 4 years ago

@AlexeiVoice Any luck reproducing this or identifying the root of it?

OleksiiVoice commented 4 years ago

Hi @rorbech. We've been able to push new version with additional logs just recently, so don't have any updates at this point unfortunately.

cmelchior commented 4 years ago

@AlexeiVoice Is there any new information you can share?

OleksiiVoice commented 4 years ago

@cmelchior We've received 6 crash reports from 4 users for the last 2 weeks. Not the whole bunch of course, but still unfortunate. Those 2 users that had 2 crashes each, had them within a second interval. Not sure what what to make of it though. According to logs, devices aren't rooted and use stock firmware. Unfortunately we weren't able to add a check to determine package install source out of the caution to not to accidentally trigger any PlayStore-policy related checks. The app is used by people on daily basis for their work, so we can't risk trigger any store's violations there. So at the end of the day the crash appears on non-rooted devices with stock firmware while the app is opened and in use. I'm sorry, I understand it's not too helpful, but that's what we have right now unfortunately.

clementetb commented 3 years ago

@AlexeiVoice

Would it be possible to take a look at the manifest file? Would it be possible to have access to the affected lock files? In case of a crash, could you fetch the file via crashlytics? Could you share all the crash logs you got for this issue? We want to check what shared info version values you get. Are there any particularities on your code that we should be aware of? Like, multi-processing, background threads, workers, content providers, heavy data processing..

If you want to keep any of that information private you can send it to clemente.tort@mongodb.com

clementetb commented 3 years ago

Closing due inactivity. Please feel free to reopen if the issue persists.