MB-19278: Fix lock-order inversion on ActiveStream::streamMutex 33/63033/6
authorDave Rigby <daver@couchbase.com>
Tue, 19 Apr 2016 13:41:06 +0000 (14:41 +0100)
committerChiyoung Seo <chiyoung@couchbase.com>
Sat, 23 Apr 2016 01:14:12 +0000 (01:14 +0000)
commita430629f25cff1bd01f1a0ed7007ba694769f1fd
treed4853628c5e7dd441eb200bbc1eec85a09f6e1c3
parent6387cef83f3d23c659f5934e243705d55ba70aae
MB-19278: Fix lock-order inversion on ActiveStream::streamMutex

ThreadSanitizer has identified a potential deadlock due to a cycle in
  the lock order graph: Cycle in lock order graph:

    M43515         => M36787      => M36848            => M43515
   [ActiveStream::   [TaskQueue::   [ExecutorThread::    [ActiveStream::
    streamMutex]      mutex]         currentTaskMutex]    streamMutex]

The crux of the problem appears to be the acquisition of streamMutex
in the destructor of ActiveStream. This is ultimately a Bad Idea - if
you still have multiple threads accessing an object when it's been
deleted then you are already into undefined behaviour.

Change-Id: I2353b5a8ed93a4f9e8cc036cb85680c185cbcc2f
Reviewed-on: http://review.couchbase.org/63033
Well-Formed: buildbot <build@couchbase.com>
Reviewed-by: Daniel Owen <owend@couchbase.com>
Tested-by: buildbot <build@couchbase.com>
src/dcp-stream.h