MobileNativeFoundation / MobileNativeFoundation/Store

[BUG] Calling store.get() in RoomDatabase.withTransaction will encounter a deadlock

Open
#453 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Kotlin
Stars
3.4k
Forks
217
Avg merge
18m
Merged PRs (30d)
4

Description

Describe the bug
When I call store.get() in the RoomDatabase.withTransaction {} and the store trigger the writer to write data into the database, a deadlock will occur. Everything is fine if the writer does not trigger or calling the store.get() outside the withTransaction {}.

To Reproduce

  1. clear the Room's table that the Store used
  2. call store.get() inside the RoomDatabase.withTransaction {}

Sample code (Full sample):

viewLifecycleOwner.lifecycleScope.launch {
    appDatabase.forumDao().deleteAll()
    // The transaction work fine if uncomment the line below
    // forumStore.get(ForumKey(id = "1"))
    appDatabase.withTransaction {
        Log.d("TEST", "Start transaction")
        forumStore.get(ForumKey(id = "1"))
        Log.d("TEST", "End transaction")
    }
}

Expected behavior

  1. According to the sample above, either the "End transaction" should print or the error log should appear

Smartphone (please complete the following information):

  • Device: Emulator Pixel_4_API_33
  • OS: Android 13
  • Store Version: 4.0.5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked full sample and reproduce the sequence: clear the Room table, then call forumStore.get() inside RoomDatabase.withTransaction. Trace the Store writer path and its Room transaction interaction. Done means the transaction reaches “End transaction” or reports an error instead of deadlocking, with a regression test for the scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
databases, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.