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

Possible deadlock in live query callback

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 3.0
    • 3.0
    • LiteCore
    • Security Level: Public
    • None
    • Jim 55
    • 5

    Description

      https://github.com/couchbase/couchbase-lite-C/issues/209

      C4Query::liveQuerier breaks the rule about calling external code while holding an internal lock. As a result there is a situation where via convoluted circular mechanisms the code can end up back in C4Query and attempt to seize the lock again, resulting in a deadlock:

      • C4Query::liveQuerierUpdated seizes lock
      • C4QueryObserverImpl::notify
      • ListenerToken observe callback
      • ListenerToken::queryChanged
      • CBLDatabase::notify
      • Above function retains the listener token passed into it
      • All other areas in the meantime release the listener token (ref count = 1)
      • At the end of notify listener token is released to 0
      • ~ListenerToken<CBLQueryChangeListener>()
      • ListenerToken<CBLQueryChangeListener>::setEnabled
      • C4QueryObserverImpl::setEnabled
      • C4Query::enableObserver deadlock

      Recommendation:  Call the observe methods without holding the lock, if possible

      Attachments

        Issue Links

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

          Activity

            People

              jimb Jim Borden
              jimb Jim Borden
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty