Store
Store copied to clipboard
[BUG] Deadlock during synchronization in MutableStore
Reproduce:
- Make unsuccessful write to store. In other words call store.write. UpdaterResult returned by post function in Updater should be something like UpdaterResult.Error.Exception(Exception(""))
- Adjust Api so that post function in Updater will return UpdaterResult.Success in next calls.
- Read data from store In other words call store.stream.
Result: No data will come to flow because deadlock happened during synchronization.
Cause of bug: Function tryEagerlyResolveConflicts is called in RealMutableStore. withThreadSafety is called in first line of the function. It calls storeLock.lock() for the first time. updateWriteRequestQueue is called in the block of withThreadSafety. Function withWriteRequestQueueLock is called in updateWriteRequestQueue. withThreadSafety is called in withWriteRequestQueueLock. It calls storeLock.lock() for the second time in the same thread that causes deadlock.
Example app. Store is used in com/example/dropboxstore/ui/screens/store/StoreViewModel.kt Store-deadlock.zip