Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash N5realm15InvalidTableRefE #4803

Closed
vcimka opened this issue Jul 7, 2021 · 8 comments · Fixed by #4828
Closed

crash N5realm15InvalidTableRefE #4803

vcimka opened this issue Jul 7, 2021 · 8 comments · Fixed by #4828

Comments

@vcimka
Copy link

vcimka commented Jul 7, 2021

SDK and version

SDK : io.realm:realm-gradle-plugin
Version: 10.6.1

Observations

  • How frequent do the crash occur? always
  • Does it happen in production or during dev/test? dev branch on production app
  • Can the crash be reproduced by you? yes
  • Can you provide instructions for how we can reproduce it? yes

Crash log / stacktrace

E/REALM: uncaught exception in notifier thread: N5realm15InvalidTableRefE: null
    Exception backtrace:
    <backtrace not supported on this platform>
    
    
    --------- beginning of crash
A/libc: /buildbot/src/android/ndk-release-r22/toolchain/llvm-project/libcxx/../../../toolchain/llvm-project/libcxxabi/src/abort_message.cpp:72: abort_message: assertion "terminating with uncaught exception of type realm::InvalidTableRef: null
    Exception backtrace:
    <backtrace not supported on this platform>" failed
A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 6392 (realm_thread), pid 6262 (com.*)

looks same
realm/realm-java#7250

@vcimka
Copy link
Author

vcimka commented Jul 15, 2021

do you plan to fix it?

@fealebenpae
Copy link
Member

Hey @Stefanos65535,

I'm sorry for not replying earlier, but we'll need more information to try and figure out what the problem is before we fix it. Is it possible to describe the steps leading up to the crash, share your schema, or code snippets of the write transaction leading up to the notifier thread crashing?

@fealebenpae fealebenpae added the More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. label Jul 15, 2021
@vcimka
Copy link
Author

vcimka commented Jul 17, 2021

use that snippet to reproduce this bug (launch it few times)

class MainActivity : AppCompatActivity(), CoroutineScope {

    override val coroutineContext: CoroutineContext = SupervisorJob() + Dispatchers.IO

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        initDb()
        observeChanges()
        launch {
            (0..10).forEach {
                saveSections()
                delay(300)
            }
        }
        launch {
            saveRoutes()
        }
    }

    private fun initDb() {
        Realm.init(applicationContext)

        val directory =
            File(applicationContext.filesDir.absolutePath + File.separator + "app_db")

        val config = RealmConfiguration.Builder()
            .directory(directory)
            .deleteRealmIfMigrationNeeded()
            .build()

        Realm.setDefaultConfiguration(config)
    }

    private fun observeChanges() {
        val realm = Realm.getDefaultInstance()

        val listener = RealmChangeListener<RealmResults<TestEntity>> {
            it.forEach { entity ->
                Log.d("Test", "${entity.id} with innerCount: ${entity.items?.size}")
            }
        }

        realm.where(TestEntity::class.java).findAllAsync().addChangeListener(listener)
    }

    private fun saveSections() {

        val realm = Realm.getDefaultInstance()
        val from = Random.nextInt(0, 100)
        val to = Random.nextInt(100, 10000)

        val entities = (from..to).realmMap {

            val innerEntities = (0..10).realmMap {
                RealmAny.valueOf(
                    TestWrappedObjectEntity(
                        id = it.toString(),
                        target = RealmAny.valueOf(
                            TestInnerEntity(
                                id = it.toLong()
                            )
                        )
                    )
                )
            }

            TestEntity(
                id = it.toLong(),
                items = innerEntities
            )
        }

        realm.executeTransaction {
            it.copyToRealmOrUpdate(entities)
        }
    }

    private fun saveRoutes() {

        val realm = Realm.getDefaultInstance()
        val from = Random.nextInt(0, 100)
        val to = Random.nextInt(100, 10000)

        val entities = (from..to).realmMap {

            TestInnerEntity(
                id = it.toLong()
            )
        }

        realm.executeTransaction {
            it.copyToRealmOrUpdate(entities)
        }
    }

    inline fun <T, R> Iterable<T>.realmMap(transform: (T) -> R): RealmList<R> {
        return mapTo(RealmList(), transform)
    }
}

  open class TestEntity(
      @PrimaryKey
      var id: Long = 0,
      var items: RealmList<RealmAny>? = null
  ) : RealmObject()
  
  open class TestWrappedObjectEntity(
    @PrimaryKey
    var id: String = "",
    var target: RealmAny? = RealmAny.nullValue(),
  ) : RealmObject()

  open class TestInnerEntity(
      @PrimaryKey
      var id: Long = 0
  ) : RealmObject()

@no-response no-response bot removed the More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. label Jul 17, 2021
@vcimka
Copy link
Author

vcimka commented Jul 20, 2021

@fealebenpae is it enough?

@fealebenpae
Copy link
Member

Hey @Stefanos65535. I've asked for help from the Android SDK to run your repro.

@vcimka
Copy link
Author

vcimka commented Jul 25, 2021

any updates? sorry but looking forward to this fix

@fealebenpae
Copy link
Member

I'm happy to say that we reproduced the issue and found a fix. We can make a realm-core release within the next week and then realm-java can follow.

@cmelchior
Copy link
Contributor

@Stefanos65535 Realm Java 10.7.1 has been released with a fix. It should be available on Maven Central shortly.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants