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

Stop replicator could cause 'database is locked' error when saving a document

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • Beryllium
    • 3.0.x
    • LiteCore
    • Security Level: Public
    • None
    • LiteCore 105
    • 1

    Description

      Failed Line:
      https://github.com/couchbase/couchbase-lite-ios/blob/release/3.1/Objective-C/Tests/ReplicatorTest%2BMain.m#L813That line is trying to save a document after the replicator is stopped.

      Log (Can't reproduce the issue when setting log level to verbose or debug):
      https://gist.github.com/pasin/c2c27d55cfe8d09328c730845fece9f5

      BThttps://gist.github.com/pasin/7dfe902fc7f5e789aacfcf2322cf781a

      Analysis:

      1. When stopping the replicator, the replicator will close its internal database (in the background thread).

      2. In the process of closing the database, we also run "PRAGMA analysis_limit=400; PRAGMA optimize" so that the query plan could be updated.

      3. The "PRAGMA analysis_limit=400; PRAGMA optimize" is expected to run very fast but it could be run a bit longer depending on data and number of indexes.

      4. However, While running "PRAGMA analysis_limit=400; PRAGMA optimize", the SQLite database is locked. As a result, this could cause a side effect if on another thread, a write the the database (e.g. saving a document) happens, the write will be errored as the database is locked.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:

                PagerDuty