Store icon indicating copy to clipboard operation
Store copied to clipboard

[BUG] Deadlock during synchronization in MutableStore

Open Marcel348 opened this issue 2 years ago • 0 comments

Reproduce:

  1. 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(""))
  2. Adjust Api so that post function in Updater will return UpdaterResult.Success in next calls.
  3. 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

Marcel348 avatar Sep 27 '23 05:09 Marcel348