Uploaded image for project: 'Couchbase Lite'
  1. Couchbase Lite
  2. CBL-4529

Error when saving documents with LiteCore error 17: must be called during a transaction

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 3.0.12
    • 3.0.11
    • LiteCore
    • Security Level: Public
    • LiteCore 107
    • 1

    Description

      This is reported by CBSE-14300.

      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:

      LiteCore throwing LiteCore error 17: must be called during a transaction

      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:

      2023-04-24 18:45:14.415045| [error]  ERROR: Assertion failed: !_inTransaction (DataFile.cc:356, in beginTransactionScope) *******************************2023-04-24 18:45:14.426974| [error]  [WS] ERROR: {135|BuiltInWebSocket} caught exception while connecting: Assertion failed: !_inTransaction *******************************2023-04-24 18:45:14.427816| [info]  [Sync]: {134} Connection closed with Unknown error 1: "Assertion failed: !_inTransaction" (state=1) *******************************2023-04-24 18:45:14.428246| [error]  [Sync] ERROR: {134|Repl} Got LiteCore error: LiteCore RemoteError, "Assertion failed: !_inTransaction" *******************************2023-04-24 18:45:14.428312| [error]  [Sync] ERROR: {65|C4Replicator} State: connecting, progress=0%, error=LiteCore RemoteError, "Assertion failed: !_inTransaction" *******************************2023-04-24 18:45:14.437224| [error]  [Sync] ERROR: {65} State: stopped, progress=0%, error=LiteCore RemoteError, "Assertion failed: !_inTransaction" *******************************  

      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 :

      2023-04-24 18:49:57.078966| [error]  ERROR: LiteCore throwing LiteCore error 17: must be called during a transaction
      2023-04-24 18:51:56.339561| [error]  ERROR: LiteCore throwing LiteCore error 17: must be called during a transaction
      2023-04-24 18:51:58.686432| [error]  ERROR: LiteCore throwing LiteCore error 17: must be called during a transaction
      2023-04-24 18:52:28.938408| [error]  ERROR: LiteCore throwing LiteCore error 17: must be called during a transaction 

      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.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              jianmin.zhao Jianmin Zhao
              pasin Pasin Suriyentrakorn
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty