Description
Based on https://github.com/couchbase/couchbase-lite-core/wiki/Thread-Safety, c4queryobs_* (except c4queryobs_create which is thread-safe) is under database-exclusive section.
Without doing that, when creating and starting multiple live queries concurrently, there could be a race condition as each live queries try to get the background database at the same time. The result of the race is that multiple background databases could be created but only the last one stays and the rest will be freed. Therefore, some live queries will hold on to the bad background database which will cause the crash when the database is used.
LiteCore Code Reference:
https://github.com/couchbase/couchbase-lite-core/blob/release/3.1/LiteCore/Database/LiveQuerier.cc#L43
https://github.com/couchbase/couchbase-lite-core/blob/release/3.1/LiteCore/Database/DatabaseImpl.cc#L410-L412
To fix this issue, the platform code needs to follow the thread safety instruction when using c4queryobs_* functions by making sure to call them under database-execlusive lock.
Attachments
Issue Links
- Clones
-
CBL-4428 Crash when starting multiple live queries concurrently
- Closed