realm / realm-core

Core database component for the Realm Mobile Database SDKs
https://realm.io
Apache License 2.0
1.02k stars 158 forks source link

Invalid top array size (ref: 2224064, array size: 655360) file size: 0 #8035

Open BlueCobold opened 6 days ago

BlueCobold commented 6 days ago

SDK and version

SDK : RealmKotlin Version: 2.2.0 (Core 14.12.0)

Observations

Crash log / stacktrace

Failed to memory buffer:Invalid top array size (ref: 2224064, array size: 655360) file size: 0, read lock size: none, read lock version: none: java.lang.IllegalStateException: [RLM_ERR_INVALID_DATABASE]: Failed to open Realm file at path "....": Failed to memory buffer:Invalid top array size (ref: 2224064, array size: 655360) file size: 0, read lock size: none, read lock version: none at io.realm.kotlin.internal.interop.CoreErrorConverter.asThrowable(SourceFile:96) at io.realm.kotlin.internal.interop.realmcJNI.realm_open(Native Method) at io.realm.kotlin.internal.interop.realmc.realm_open(SourceFile:1) at io.realm.kotlin.internal.interop.RealmInterop.realm_open(SourceFile:41) at io.realm.kotlin.internal.ConfigurationImpl.openRealm$lambda$0(SourceFile:18) at io.realm.kotlin.internal.ConfigurationImpl.a(SourceFile:1) at io.realm.kotlin.internal.b.invoke(SourceFile:1) at io.realm.kotlin.internal.interop.NativePointerKt.use(SourceFile:11) at io.realm.kotlin.internal.ConfigurationImpl.openRealm$suspendImpl(SourceFile:20) at io.realm.kotlin.internal.ConfigurationImpl.openRealm(SourceFile:1) at io.realm.kotlin.internal.RealmImpl$1.invokeSuspend(SourceFile:138) at kotlin.coroutines.jvm.internal.a.resumeWith(SourceFile:12) at kotlinx.coroutines.DispatchedTask.run(SourceFile:129) at kotlinx.coroutines.EventLoopImplBase.processNextEvent(SourceFile:82) at kotlinx.coroutines.BlockingCoroutine.joinBlocking(SourceFile:27) at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(SourceFile:77) at kotlinx.coroutines.BuildersKt.runBlocking(SourceFile:1) at io.realm.kotlin.internal.platform.CoroutineUtilsSharedJvmKt.runBlocking(SourceFile:11) at io.realm.kotlin.internal.platform.CoroutineUtilsSharedJvmKt.runBlocking$default(SourceFile:7) at io.realm.kotlin.internal.RealmImpl.\u003cinit\u003e(SourceFile:15) at io.realm.kotlin.internal.RealmImpl.\u003cinit\u003e(SourceFile:1) at io.realm.kotlin.internal.RealmImpl$Companion.create$io_realm_kotlin_library(SourceFile:9) at io.realm.kotlin.Realm$Companion.open(SourceFile:10)

Steps & Code to Reproduce

I sadly do not have the file in question. However, a broken topRef means there are still bugs which make Realm not ACID and a reported file size of 0 means the error message is incorrect as well, because if it was 0 bytes in size, there would not be a readable topRef at all.

sync-by-unito[bot] commented 6 days ago

➤ PM Bot commented:

Jira ticket: RCORE-2260

nicola-cab commented 5 days ago

Hello @BlueCobold thanks for reporting this. Without the file however it is almost impossible to understand what happened.

Clearly, the top ref array is not valid: https://github.com/realm/realm-core/blob/c729fc803dc64753028f739bd2faf9d3f30bcad3/src/realm/group.cpp#L493

I can only think about something bad happening when a transaction was committed. Do you have more information on your side that can give us some tips about how to try to reproduce this issue?

BlueCobold commented 5 days ago

I'm afraid I can not provide more info that this crash report. I understand it's probably super hard to identify. I can say that access to the realm is temporary opened and closed in a single-threaded exclusive way. If it's impossible to find a reason for such an invalid top-ref, I'm sure you can at least correct the wrong error-message which claims the file-size to be 0, which is logically impossible if a top-ref can be read.

jedelbo commented 4 days ago

The file size we are referring to here is the logical file size that is stored in the top array. So if the top ref is pointing to some invalid array, that size can perfectly fine be 0. Unfortunately we have not been able to find the reason why the top ref can be wrong. Can you tell on which platform this is happening? Historically we have only seen these kind of problems on iOS. So the theory is that something weird is going on in the file system - possibly if the platform crashes.

BlueCobold commented 4 days ago

Ah, I see. So it's a confusing message, because it says "array size: 655360), file size: 0".

It happened on Android.

nicola-cab commented 4 days ago

@jedelbo I may be wrong (because I don't recall in detail what we did). But as far as I remember, we only added the extra msync call for IOS and left the management of the dirty pages untouched for the other platforms. I repeat, I might be wrong on this. Probably this is just speculation, though.

sync-by-unito[bot] commented 3 days ago

➤ jedelbo commented:

Without having the file, I can't see how we can move forward on this issue, I I will close it.

BlueCobold commented 2 days ago

@jedelbo The issue persists. I keep getting reports.

Failed to open Realm file at path "...": Failed to memory buffer:Invalid top array size (ref: 2882016, array size: 16777215) file size: 108086541928145056, read lock size: none, read lock version: none