Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-19222

ep-engine: race condition in TaskQueue shutdown

    XMLWordPrintable

Details

    • Untriaged
    • Unknown
    • KV: April 13 - April 26

    Description

      There is a bug in the use of ExecutorThread.state when sleeping a TaskQueue - TaskQueue::_doSleep() doesn't atomically transition the state from RUNNING -> SLEEPING. This can cause a deadlock when shutting down a ExecutorThread:

          
              Thread A:                           Thread B:
              --------------------------------    ------------------------------
              if (t.state == RUNNING) {  // true
                                                  t.state = SHUTDOWN
                  t.state = SLEEPING              cb_join_thread(Thread A)
                                                  // wait forever
              ...
              if (t.state == SHUTDOWN) { // FALSE
                exit(0) // NEVER REACHED
              }
      

      Fix by changing ExecutorThread.state to be an AtomicValue, and use compare-and-exchange to move from RUNNING -> SLEEPING (and SLEEPING -> RUNNING).

      Note: This was previously fixed in 4.0.0 prior to release - see http://review.couchbase.org/43134 Backporting as 3.x ThreadSanitizer runs have flagged it as an issue there also.

      Attachments

        Issue Links

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

          Activity

            People

              drigby Dave Rigby (Inactive)
              drigby Dave Rigby (Inactive)
              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