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

Realm java always crash. #7827

Closed Lemac closed 1 year ago

Lemac commented 1 year ago

How frequently does the bug occur?

Sometimes

Description

cannot reproduce manually, but this bug always reproduce. From the log, I can see the db file is broken.

Stacktrace & log output

java.lang.RuntimeException: Unable to resume activity {com.gspot.video/com.gspot.ui.MainActivity}: java.lang.RuntimeException: flock() failed: Bad file descriptor in /tmp/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 144
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3815)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3847)
    at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1836)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6702)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
Caused by: java.lang.RuntimeException: flock() failed: Bad file descriptor in /tmp/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 144
    at io.realm.internal.OsSharedRealm.nativeCommitTransaction(Native Method)
    at io.realm.internal.OsSharedRealm.commitTransaction(OsSharedRealm.java:293)
    at io.realm.BaseRealm.commitTransaction(BaseRealm.java:460)
    at io.realm.Realm.commitTransaction(Realm.java:138)
    at com.gspot.db.GSpotRealmDBHelper.getVideoSettings(GSpotRealmDBHelper.java:899)
    at com.gspot.ui.HomepageFragment.initStorage(HomepageFragment.java:270)
    at com.gspot.ui.HomepageFragment.onResume(HomepageFragment.java:95)
    at androidx.fragment.app.Fragment.performResume(Fragment.java:3039)
    at androidx.fragment.app.FragmentStateManager.resume(FragmentStateManager.java:607)
    at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:306)
    at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:112)
    at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1647)
    at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3128)
    at androidx.fragment.app.FragmentManager.dispatchResume(FragmentManager.java:3086)
    at androidx.fragment.app.FragmentController.dispatchResume(FragmentController.java:273)
    at androidx.fragment.app.FragmentActivity.onResumeFragments(FragmentActivity.java:458)
    at androidx.fragment.app.FragmentActivity.onPostResume(FragmentActivity.java:447)
    at androidx.appcompat.app.AppCompatActivity.onPostResume(AppCompatActivity.java:240)
    at android.app.Activity.performResume(Activity.java:7317)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3807)
    ... 11 more
java.lang.RuntimeException: flock() failed: Bad file descriptor in /tmp/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 144
    at io.realm.internal.OsSharedRealm.nativeCommitTransaction(Native Method)
    at io.realm.internal.OsSharedRealm.commitTransaction(OsSharedRealm.java:293)
    at io.realm.BaseRealm.commitTransaction(BaseRealm.java:460)
    at io.realm.Realm.commitTransaction(Realm.java:138)
    at com.gspot.db.GSpotRealmDBHelper.getVideoSettings(GSpotRealmDBHelper.java:899)
    at com.gspot.ui.HomepageFragment.initStorage(HomepageFragment.java:270)
    at com.gspot.ui.HomepageFragment.onResume(HomepageFragment.java:95)
    at androidx.fragment.app.Fragment.performResume(Fragment.java:3039)
    at androidx.fragment.app.FragmentStateManager.resume(FragmentStateManager.java:607)
    at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:306)
    at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:112)
    at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1647)
    at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3128)
    at androidx.fragment.app.FragmentManager.dispatchResume(FragmentManager.java:3086)
    at androidx.fragment.app.FragmentController.dispatchResume(FragmentController.java:273)
    at androidx.fragment.app.FragmentActivity.onResumeFragments(FragmentActivity.java:458)
    at androidx.fragment.app.FragmentActivity.onPostResume(FragmentActivity.java:447)
    at androidx.appcompat.app.AppCompatActivity.onPostResume(AppCompatActivity.java:240)
    at android.app.Activity.performResume(Activity.java:7317)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3807)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3847)
    at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1836)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6702)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)

Can you reproduce the bug?

Sometimes

Reproduction Steps

cannot reproduce manually, but this bug always reproduce. From the log, I can see the db file is broken.

Version

10.11.0

What Atlas App Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

android 9

Build environment

Android Studio version: Android Studio Electric Eel | 2022.1.1 Patch 2 Android Build Tools version: 3.6.4 Gradle version: 6.1

clementetb commented 1 year ago

Thanks for reporting the issue. The issue is generated in the native side of the library, thus we require a native stack trace log, it looks similar to this.

rorbech commented 1 year ago

Seems to be rethrown from the JNI wrapper, so there wont be any native stack trace in the logs.

Most likely the file is just deleted when the transaction is about to be committed to storage. @Lemac In which cases do your app delete the realm file? And are you doing it through normal file system operations? In that case you could try using Realm.deleteRealm(...) to ensure that the various operations are performed mutual exclusively.

github-actions[bot] commented 1 year ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.