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

Unrecoverable error. msync() failed #5810

Closed jainpiyush19 closed 4 years ago

jainpiyush19 commented 6 years ago

I am getting this error in my app.

We have not been able to reproduce this issue in our test devices. we noticed this exception while analyzing crashes on production devices.

Caused by io.realm.exceptions.RealmError: Unrecoverable error. msync() failed: I/O error in /Users/cm/Realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 144
       at io.realm.internal.OsSharedRealm.nativeCommitTransaction(OsSharedRealm.java)
       at io.realm.internal.OsSharedRealm.commitTransaction(OsSharedRealm.java:286)
       at io.realm.BaseRealm.commitTransaction(BaseRealm.java:400)
       at io.realm.Realm.commitTransaction(Realm.java:135)
       at io.realm.Realm.executeTransaction(Realm.java:1395)
       at com.application.zomato.base.utils.RealmHelper.insertOrUpdate_aroundBody12(RealmHelper.java:179)
       at com.application.zomato.base.utils.RealmHelper.insertOrUpdate_aroundBody13$advice(RealmHelper.java:56)
       at com.application.zomato.base.utils.RealmHelper.insertOrUpdate(RealmHelper.java:1)
       at com.application.zomato.base.connections.sync.ZSyncAdapter.syncDataToServer(ZSyncAdapter.java:186)
       at com.application.zomato.base.connections.sync.ZSyncAdapter.lambda$run$0$ZSyncAdapter(ZSyncAdapter.java:88)
       at com.application.zomato.base.connections.sync.ZSyncAdapter$$Lambda$0.call(Unknown Source)
       at rx.internal.util.ActionSubscriber.onNext(ActionSubscriber.java:39)
       at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:134)
       at rx.internal.operators.OnSubscribeTimerPeriodically$1.call(OnSubscribeTimerPeriodically.java:52)
       at rx.internal.schedulers.SchedulePeriodicHelper$1.call(SchedulePeriodicHelper.java:72)
       at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:230)
       at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
       at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
       at java.lang.Thread.run(Thread.java:818)

Realm version : 4.3.1 Affected android versions : 5.1, 4.4.4, 4.4.2

cmelchior commented 6 years ago

Any indication of how much it is crashing? In any case, this is definitely a device issue and not an Android version one. Do you have a list of devices affected?

jainpiyush19 commented 6 years ago

It has crashed on different devices, So I am not sure if it is a device issue. Example Galaxy Tab3 Lite 7.0 Allwinner-Tablet (Posiflex) - android 4.4.4 PC BOX

jainpiyush19 commented 6 years ago

Also this crash is occuring on 1 device

Non-fatal Exception: io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.application.zomato.base/files/default.realm': Not a Realm file. (Not a Realm file) (/data/data/com.application.zomato.base/files/default.realm) in /Users/cm/Realm/realm-java-release/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:184)
       at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:254)
       at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:244)
       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 com.application.zomato.base.utils.RealmHelper.getInstance_aroundBody2(RealmHelper.java:100)
       at com.application.zomato.base.utils.RealmHelper.getInstance_aroundBody3$advice(RealmHelper.java:56)
       at com.application.zomato.base.utils.RealmHelper.getInstance(RealmHelper.java:1)
       at com.application.zomato.base.utils.RealmHelper.insertOrUpdate_aroundBody12(RealmHelper.java:178)
       at com.application.zomato.base.utils.RealmHelper.insertOrUpdate_aroundBody13$advice(RealmHelper.java:56)
       at com.application.zomato.base.utils.RealmHelper.insertOrUpdate(RealmHelper.java:1)
       at com.application.zomato.base.modules.factory.ParseOrder.lambda$insertOrUpdateOrder$2$ParseOrder(ParseOrder.java:296)
       at com.application.zomato.base.modules.factory.ParseOrder$$Lambda$2.call(Unknown Source)
       at rx.internal.operators.OnSubscribeFromCallable.call(OnSubscribeFromCallable.java:48)
       at rx.internal.operators.OnSubscribeFromCallable.call(OnSubscribeFromCallable.java:33)
       at rx.Observable.unsafeSubscribe(Observable.java:10256)
       at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call(OperatorSubscribeOn.java:100)
       at rx.android.schedulers.LooperScheduler$ScheduledAction.run(LooperScheduler.java:107)
       at android.os.Handler.handleCallback(Handler.java:733)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:136)
       at android.os.HandlerThread.run(HandlerThread.java:61)
AM0647 commented 6 years ago

Hello.

The above bug made it's appearence in my Android app today as well. It is extremely rare as it has happened once in over 50k sessions of my app. Here is the code and the exception message as shown in Crashlytics (since the crash didn't happen to me but to a user).

Log.d("Receiver","forceupdate begins now");
                RealmResults<StoreUpdateResponse> StoreUpdateResponseResults = realm.where(StoreUpdateResponse.class).findAll();

                if(StoreUpdateResponseResults.size() == 0){              // first time we save the response

                    Log.d("Receiver","Table empty");

                    realm.beginTransaction();
                    realm.createObjectFromJson(StoreUpdateResponse.class,force_update_response);
                    realm.commitTransaction();

                }else {

                    Log.d("Receiver","Table not empty. Delete and write new");

                    realm.beginTransaction();
                    StoreUpdateResponseResults.deleteAllFromRealm();
                    realm.commitTransaction();

                    realm.beginTransaction();
                    realm.createObjectFromJson(StoreUpdateResponse.class,force_update_response);
                    realm.commitTransaction();

                }

The problem seems to be with the realm.commitTransaction(); after StoreUpdateResponseResults.deleteAllFromRealm();.

Here is the Crashlytics crash report

Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. msync() failed: Interrupted system call in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 144
       at io.realm.internal.SharedRealm.nativeCommitTransaction(SharedRealm.java)
       at io.realm.internal.SharedRealm.commitTransaction(SharedRealm.java:251)
       at io.realm.BaseRealm.commitTransaction(BaseRealm.java:400)
       at io.realm.Realm.commitTransaction(Realm.java:134)
       at com.e_analysis.AlphaPro.MobileTicketing.TicketIssuanceActivityAstiko$41.onReceive(TicketIssuanceActivityAstiko.java:13494)
       at android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:308)
       at android.support.v4.content.LocalBroadcastManager.access$000(LocalBroadcastManager.java:46)
       at android.support.v4.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:118)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6119)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Something to keep in mind : The above code is inside a broadcast receiver. When the receiver get's notified by my background thread it performs the operations it has to do. Meanwhile the user could in theory be in a different activity and so on. Could this has something to do with it?

PS: It's my first post here so sorry if my message is not stylized properly. PS2: I am currently using Realm version 4.1.0. PS3: The device on which the crash occured is a Lenovo TB-8504F tablet.

0xMineGo800m commented 5 years ago

I'm encountering this issue as well:

Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. msync() failed: I/O error in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 144
       at io.realm.internal.OsSharedRealm.nativeCommitTransaction(OsSharedRealm.java)
       at io.realm.internal.OsSharedRealm.commitTransaction(OsSharedRealm.java:273)
       at io.realm.BaseRealm.commitTransaction(BaseRealm.java:415)
       at io.realm.Realm.commitTransaction(Realm.java:145)
       at io.realm.Realm.executeTransaction(Realm.java:1494)

A single user for now. User has a Galaxy S6 Edge device (running Android: 7.0). App is running Realm version 5.8.0.

Any updates on this crash?

vovan888 commented 5 years ago

Realm 5.9.0 - same crash:

Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. msync() failed: I/O error in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 144
       at io.realm.internal.OsSharedRealm.nativeCommitTransaction(SourceFile)
       at io.realm.internal.OsSharedRealm.commitTransaction(SourceFile:273)
       at io.realm.BaseRealm.commitTransaction(SourceFile:414)
       at io.realm.Realm.commitTransaction(SourceFile:143)
       at io.realm.Realm.executeTransaction(SourceFile:1432)
       at com.stbbox.launcher.pvr.PvrService.deleteStaleLocalRecordings(SourceFile:63)
       at com.stbbox.launcher.pvr.PvrService$ServiceHandler.handleMessage(SourceFile:176)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.os.HandlerThread.run(HandlerThread.java:61)
3c133ps3d commented 5 years ago

Galaxy Note Pro 12.2, Android 9.0

Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. msync() failed: I/O error in io_realm_internal_SharedGroup.cpp line 188
       at io.realm.internal.SharedGroup.nativeCommitAndContinueAsRead(SharedGroup.java)
       at io.realm.internal.SharedGroup.commitAndContinueAsRead + 149(SharedGroup.java:149)
       at io.realm.internal.ImplicitTransaction.commitAndContinueAsRead + 62(ImplicitTransaction.java:62)
       at io.realm.internal.SharedGroupManager.commitAndContinueAsRead + 118(SharedGroupManager.java:118)
       at io.realm.BaseRealm.commitTransaction + 367(BaseRealm.java:367)
       at io.realm.BaseRealm.commitTransaction + 347(BaseRealm.java:347)
       at io.realm.Realm.commitTransaction + 122(Realm.java:122)
clementetb commented 4 years ago

Realm-Java 6 and upwards fixes this issue. If you are using a lower realm version and experience this issue please upgrade your realm.

Closing this issue as it is fixed. Please reopen the issue if you experience this crash on Realm v6 or higher.

wverdese commented 3 years ago

I have seen more than 1.3K crashes in production only in the last month. 😕

Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. msync() failed: I/O error in /Users/cm/Realm/realm-java-release/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.internal.OsSharedRealm.getInstance(OsSharedRealm.java:231)
       at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:337)
       at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:290)
       at io.realm.Realm.getInstance(Realm.java:428)
       at com.airthings.airthings.persistence.RealmManager.<init>(RealmManager.kt:68)
       at com.airthings.airthings.di.module.CoreServicesModule.provideRealmConfigurationManager(CoreServicesModule.kt:33)
       at com.airthings.airthings.di.module.CoreServicesModule_ProvideRealmConfigurationManagerFactory.get(CoreServicesModule_ProvideRealmConfigurationManagerFactory.java:25)
       at com.airthings.airthings.di.module.CoreServicesModule_ProvideRealmConfigurationManagerFactory.get(CoreServicesModule_ProvideRealmConfigurationManagerFactory.java:10)
       at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
       at com.airthings.airthings.di.module.RepositoryModule_ProvideAuthRepositoryFactory.get(RepositoryModule_ProvideAuthRepositoryFactory.java:37)
       at com.airthings.airthings.di.module.RepositoryModule_ProvideAuthRepositoryFactory.get(RepositoryModule_ProvideAuthRepositoryFactory.java:12)
       at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
       at com.airthings.airthings.di.module.CoreServicesModule_ProvidesOkHttpFactory.get(CoreServicesModule_ProvidesOkHttpFactory.java:36)
       at com.airthings.airthings.di.module.CoreServicesModule_ProvidesOkHttpFactory.get(CoreServicesModule_ProvidesOkHttpFactory.java:12)
       at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
       at com.airthings.airthings.di.module.CoreServicesModule_AirthingsApiFactory.get(CoreServicesModule_AirthingsApiFactory.java:30)
       at com.airthings.airthings.di.module.CoreServicesModule_AirthingsApiFactory.get(CoreServicesModule_AirthingsApiFactory.java:11)
       at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
       at com.airthings.airthings.di.component.DaggerAppComponent.providesAirthingsApi(DaggerAppComponent.java:608)
       at com.airthings.airthings.AirthingsApp$onCreate$1.invokeSuspend(AirthingsApp.kt:103)
       at com.airthings.airthings.AirthingsApp$onCreate$1.invoke(:10)
       at com.airthings.airthings.utils.FuncsKt$uiDispatch$1.invokeSuspend(Funcs.kt:84)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:201)
       at android.os.Looper.loop(Looper.java:288)
       at android.app.ActivityThread.main(ActivityThread.java:7829)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:982)

It's happening only on Android 10, 11, 12. I'm on Realm 6.0.2.