realm-kotlin: Crash in RealmSet query

Hello there !

I’ve got a weird crash when querying a RealmSet.

The Thread object contains a messagesIds :

var messagesIds: RealmSet<String> = realmSetOf()

I’m trying to get all threads in Realm that contains in their messagesIds at list 1 messageId from the input Set :

private fun getThreadsQuery(input: Set<String>, realm: TypedRealm): RealmQuery<Thread> {
    val byMessagesIds = "ANY ${Thread::messagesIds.name} IN {${input.joinToString { "'$it'" }}}"
    return realm.query(byMessagesIds)
}

And it works !

But sometimes, the query crashes. I was not able to understand why, I logged the data and everything seems fine. It looks random, never on the same item, and I don’t really understand the error message.

I’ve just started very recently to use RealmSets, so I don’t really know if there’s any specific aspect to them, compared to RealmLists.

The code is available here on the branch realmBug : https://github.com/Infomaniak/android-mail/tree/realmBug

Stacktrace below :

10:54:41.000 REALM                 E  /Users/realm/workspace-realm-kotlin/main/packages/external/core/src/realm/mixed.cpp:337: [realm-core-13.1.2] Assertion failed: false && "Compare not supported for this column type"
                                      <backtrace not supported on this platform>!!! IMPORTANT: Please report this at https://github.com/realm/realm-core/issues/new/choose
--------- beginning of crash
10:54:41.134 libc                  A  Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 21464 (2-1901061.realm), pid 21370 (infomaniak.mail)
10:54:41.424 DEBUG                 A  Cmdline: com.infomaniak.mail
10:54:41.424                       A  pid: 21370, tid: 21464, name: 2-1901061.realm  >>> com.infomaniak.mail <<<
10:54:41.424                       A        #01 pc 0000000000da7bbc  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #02 pc 0000000000da7e04  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #03 pc 0000000000da7c8c  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #04 pc 0000000000cbc110  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #05 pc 00000000006b7044  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #06 pc 00000000008dc35c  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #07 pc 0000000000ce6094  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #08 pc 0000000000ce2b04  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #09 pc 0000000000ce27e0  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #10 pc 0000000000af7628  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #11 pc 0000000000afd1e4  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #12 pc 0000000000afd120  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #13 pc 0000000000afd0d0  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #14 pc 0000000000bd5fe0  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #15 pc 0000000000bd5e08  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #16 pc 0000000000bd7244  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #17 pc 0000000000af8f98  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #18 pc 0000000000af9c7c  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #19 pc 0000000000afa2e0  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #20 pc 000000000068c078  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #21 pc 000000000068f90c  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #22 pc 00000000005f48ac  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #23 pc 00000000005e8a84  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #24 pc 00000000005e8a30  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (realm_results_count+52) (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #25 pc 0000000000585f58  /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!librealmc.so (Java_io_realm_kotlin_internal_interop_realmcJNI_realm_1results_1count+116) (BuildId: 666549597b05bcac0372d465a1219f7ac49f20c8)
10:54:41.424                       A        #28 pc 00000000004aca90  [anon:dalvik-classes.dex extracted in memory from /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk] (io.realm.kotlin.internal.interop.realmc.realm_results_count+0)
10:54:41.424                       A        #30 pc 00000000004a3eb6  [anon:dalvik-classes.dex extracted in memory from /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk] (io.realm.kotlin.internal.interop.RealmInterop.realm_results_count+26)
10:54:41.424                       A        #32 pc 0000000000497cf8  [anon:dalvik-classes.dex extracted in memory from /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk] (io.realm.kotlin.internal.RealmResultsImpl.getSize+8)
10:54:41.424                       A        #34 pc 0000000000108c74  [anon:dalvik-classes26.dex extracted in memory from /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!classes26.dex] (kotlin.collections.AbstractCollection.size+0)
10:54:41.424                       A        #37 pc 00000000000093e4  /data/data/com.infomaniak.mail/code_cache/.overlay/base.apk/classes20.dex (com.infomaniak.mail.data.cache.mailboxContent.MessageController.createMultiMessagesThreads+144)
10:54:41.424                       A        #39 pc 00000000000086d6  /data/data/com.infomaniak.mail/code_cache/.overlay/base.apk/classes20.dex (com.infomaniak.mail.data.cache.mailboxContent.MessageController$handleAddedUids$1$1.invoke+74)
10:54:41.424                       A        #41 pc 0000000000008722  /data/data/com.infomaniak.mail/code_cache/.overlay/base.apk/classes20.dex (com.infomaniak.mail.data.cache.mailboxContent.MessageController$handleAddedUids$1$1.invoke+6)
10:54:41.424                       A        #43 pc 000000000049b020  [anon:dalvik-classes.dex extracted in memory from /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk] (io.realm.kotlin.internal.SuspendableWriter$write$2.invokeSuspend+228)
10:54:41.424                       A        #45 pc 000000000016b3ea  [anon:dalvik-classes26.dex extracted in memory from /data/app/~~LLOj0LBHvp22mRf3jIABXg==/com.infomaniak.mail-OaLAKnoLR5y4It8dJzFR-w==/base.apk!classes26.dex] (kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith+42)
---------------------------- PROCESS ENDED (21370) for package com.infomaniak.mail ----------------------------

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 26 (15 by maintainers)

Most upvoted comments

Awaiting merge of the fix in core https://github.com/realm/realm-core/pull/6545

This is somehow related to being a query on a mutable realm. I haven’t been able to pin point the exact issue, but if I traverse the messages in the reverse order then it doesn’t crash. Once the threading details is initially updated and persisted then it doesn’t happen anymore even though traversed in the original order. So it doesn’t seem to be the actual query but some state dependant on previous updates when doing the transaction. The amount of updates done per query is quite large, so it is really difficult to see a pattern/relation. @JorisBodin Are you able to supply a smaller reproduction dataset and eliminate any of the intermediate update operations?

@rorbech I tested it and I’m on the same analysis as you. When I do a reverse foreach it seems to work, or when I remove the updates in the loop, it also seems to work.

I also noticed that when the crash happens, it’s on an object that was previously inserted in realm. Is it possible that the object is still being transacted because of all the transactions that are done in the loop, and that it is pending or in progress? And so we query it and it creates the crash?

In this case the reverse would work in our current dataset because the object that causes concern would be processed first, and the other elements have no common keys.

On the other hand a small dataset doesn’t seem feasible, you need enough data to make it work, with transaction updates in the loop.

@rorbech I sent an email to realm-help@mongodb.com

@JorisBodin No, I have just reopened this one. I am still not able to reproduce by replicating parts of your schema, some artificial test data and your failing query. Would you be able to share a realm file where you see this behavior? There might be some indicators if we can pull the schema and inspect the data. You can send it to realm-help@mongodb.com

We check to make you this, we reproduce on a confidential email address. The complexity is to create one with non-confidential data that reproduces the bug.