realm-java: Wrong transactional state (no active transaction, wrong type of transaction, or transaction already in progress) io.realm.internal.OsObject.nativeStartListening
Goal
Understand why this happens, and make it not happen
Actual Results
We have a live app that crashes for about 1% of our users, when inserting objects in a transaction. Unfortunately we cannot find a way to reproduce the issue ourselves in our tests. The Realm message is Wrong transactional state (no active transaction, wrong type of transaction, or transaction already in progress)
.
Steps & Code to Reproduce
Here is a snippet of what we do (not the actual code, but very close):
fun doAllTheInserts(...) {
launch(coroutineUIContext) {
insertAllA(objectsA)
insertAllB(objectsB)
insertAllC(objectsC) // <- crash here
// etc...
}
}
fun insertAllC(objects: List<C>) = realm.executeTransaction { realm.copyToRealmOrUpdate(objects) }
As you can see, we insert several types of objects, in a transaction, in the main thread, and on one of the insertions, in the middle, the error sometimes occurs.
Fatal Exception: java.lang.IllegalStateException: Wrong transactional state (no active transaction, wrong type of transaction, or transaction already in progress)
at io.realm.internal.OsObject.nativeStartListening(SourceFile)
at io.realm.internal.OsObject.setObserverPairs(SourceFile:147)
at io.realm.ProxyState.registerToObjectNotifier(SourceFile:179)
at io.realm.ProxyState.onQueryFinished(SourceFile:201)
at io.realm.internal.PendingRow.notifyFrontEnd(SourceFile:244)
at io.realm.internal.PendingRow.access$000(SourceFile:20)
at io.realm.internal.PendingRow$1.onChange(SourceFile:48)
at io.realm.internal.PendingRow$1.onChange(SourceFile:45)
at io.realm.internal.ObservableCollection$RealmChangeListenerWrapper.onChange(SourceFile:39)
at io.realm.internal.ObservableCollection$CollectionObserverPair.onChange(SourceFile:20)
at io.realm.internal.ObservableCollection$Callback.onCalled(SourceFile:64)
at io.realm.internal.ObservableCollection$Callback.onCalled(SourceFile:54)
at io.realm.internal.ObserverPairList.foreach(SourceFile:109)
at io.realm.internal.OsResults.notifyChangeListeners(SourceFile:451)
at io.realm.internal.OsSharedRealm.nativeBeginTransaction(SourceFile)
at io.realm.internal.OsSharedRealm.beginTransaction(SourceFile:269)
at io.realm.BaseRealm.beginTransaction(SourceFile:403)
at io.realm.Realm.beginTransaction(SourceFile:146)
at io.realm.Realm.executeTransaction(SourceFile:1417)
at xxxx.insertAll(SourceFile:9)
at yyyy$1.doResume(SourceFile:216)
at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(SourceFile:42)
at kotlinx.coroutines.experimental.DispatchedTask$DefaultImpls.run(SourceFile:150)
at kotlinx.coroutines.experimental.DispatchedContinuation.run(SourceFile:14)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
I don’t see any reason why any transaction would be ongoing at that moment.
Please don’t hesitate to ask if I can add any information that could help investigate this.
Version of Realm and tooling
Realm version(s): 5.4.1
Realm Sync feature enabled: No
Android Studio version: irrelevent
Android Build Tools version: 27.0.3
Gradle version: 4.10.2
Which Android version and device(s): Mostly Samsung high end (Galaxy s9/s8), and mostly Android 8 and 7.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (9 by maintainers)
Yes.