MobileNativeFoundation / MobileNativeFoundation/Store
[BUG] Calling store.get() in RoomDatabase.withTransaction will encounter a deadlock
Nobody has claimed this yet.
- 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
- clear the Room's table that the Store used
- call
store.get()inside theRoomDatabase.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
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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