Error when saving documents with LiteCore error 17: must be called during a transaction
Description
This is reported by .
Platform: CBL-C 3.0.11 running on Android / iOS via Flutter plugin.
Summary of Scenarios:
1. Replicator connecting to SG is started.
2. SG responded with a session cookie to be saved into the cookie storage.
3. At the same time, the application saved documents into the database.
4. The application received the error as follows:
From the customer logs and analysis, the issue happened after the Replicator's BuiltInWebSocket caught the !_inTransaction (DataFile.cc:356, in beginTransactionScope) assertion failure while connecting to SG as the log below:
The only thing that is touching the database during the connecting state is saving the cookies and the customer have found that the code that saves the cookies into the database is called without locking:
After the assertion failure from the BuiltInWebSocket, a series of errors from saving documents occurred :
From the code point of view, that happened because after the assertion failure, the ExclusiveTransaction object will be destructed which will end the transaction with the _inTransaction flag reset.
Build couchbase-lite-c-3.1.1-3 contains couchbase-lite-core commit 61f0a81 with commit message: : Error when saving documents with LiteCore error 17: must be called during a transaction (#1805)
CB robot June 7, 2023 at 4:18 PM
Build couchbase-lite-ios-3.1.1-3 contains couchbase-lite-core commit 61f0a81 with commit message: : Error when saving documents with LiteCore error 17: must be called during a transaction (#1805)
CB robot June 7, 2023 at 12:07 AM
Build couchbase-lite-core-3.1.1-7 contains couchbase-lite-core commit 61f0a81 with commit message: : Error when saving documents with LiteCore error 17: must be called during a transaction (#1805)
Fixed
Pinned fields
Click on the next to a field label to start pinning.
This is reported by .
Platform: CBL-C 3.0.11 running on Android / iOS via Flutter plugin.
Summary of Scenarios:
1. Replicator connecting to SG is started.
2. SG responded with a session cookie to be saved into the cookie storage.
3. At the same time, the application saved documents into the database.
4. The application received the error as follows:
From the customer logs and analysis, the issue happened after the Replicator's BuiltInWebSocket caught the !_inTransaction (DataFile.cc:356, in beginTransactionScope) assertion failure while connecting to SG as the log below:
The only thing that is touching the database during the connecting state is saving the cookies and the customer have found that the code that saves the cookies into the database is called without locking:
https://github.com/couchbase/couchbase-lite-core/blob/9dc6810b92c0970c3c7f3fca62799885448e8dfa/Networking/WebSockets/BuiltInWebSocket.cc#L336C10-L339
After the assertion failure from the BuiltInWebSocket, a series of errors from saving documents occurred :
From the code point of view, that happened because after the assertion failure, the ExclusiveTransaction object will be destructed which will end the transaction with the _inTransaction flag reset.
https://github.com/couchbase/couchbase-lite-core/blob/release/lithium/LiteCore/Storage/DataFile.cc#L456
Please find full logs and more description from the CBSE ticket.