Concurrency issues when running on unity
I am having problems running operations on LiteDB across multiple threads. The issues seem to be with the ReaderWriterLockSlim class on mono (at least unity's implementation)
I am attaching a log file which shows LiteDB's full output - sorry for the cluttered log - this output is redirected to unity's output and it already took some work cutting this down to what it is now.
Essentially these are the steps
1> initial creation of DB on main thread 2> Upsert is performed on background thread - this seems fine 3> Count queries / range queries are made - all ok 4> Delete on background thread - this seems to complete ok 5> Shrink op
the shrink also to return, although there seems to be a write happening after this which hangs the app for 60 seconds before I see a LiteException stating 11:24:32.8835 [ERROR] Timeout. Database is locked for more than 00:01:00.
If I skip 1> and just do a delete on separate thread then the call to delete on the collection seems to hang (again roughly taking around 60 seconds as you can see from the timestamps, and then it fails and I see this
11:53:27.5583 [ERROR] Calling ExitWriterLock when no write lock is held
I haven't been able to replicate in a more simplistic scenario.
LiteDB-Editor-Cutdown.log.txt LiteDB-Editor-Cutdown-Only Delete.log.txt
I have since found that these issues only occur when using collections across multiple threads. It's ok to use on the main thread or a background thread. This could perhaps be down to LockService (there is a comment in the code to say Shared locks are not thread safe) The fact I can use on a background thread perhaps means this is a nice to have rather than essential problem
Hi! With the objective of organizing our issues, we are closing old unsolved issues. Please check the latest version of LiteDB and open a new issue if your problem/question/suggestion still applies. Thanks!