MB-19153: Break circular dependency while deleting bucket 99/62699/4
authorabhinavdangeti <abhinav@couchbase.com>
Tue, 12 Apr 2016 01:28:37 +0000 (18:28 -0700)
committerChiyoung Seo <chiyoung@couchbase.com>
Tue, 12 Apr 2016 18:34:28 +0000 (18:34 +0000)
commit3bd9fa40f9cc597ffc6b4f9743c75bf4f8f6e4d6
treec99ba58b42e6635450cb063fcd081832f90753a8
parent6e38fe8891e4e63996cecaa55b0e23accaf6f83b
MB-19153: Break circular dependency while deleting bucket

As part of unregistering the last bucket, when stopTaskGroup
is invoked, all the running threads will cancelled. In this
issue reported, when DcpBackfill was closed, the ref count of
the DcpProducer whose reference it was holding on to became
zero, causing its destructor to be invoked. In the DcpProducer's
destructor, an attempt was made to cancel the checkpoint creator
task which needed to acquire the executorpool's tMutex that
unregisterBucket had already acquired.

Reproduction steps:
<delete_bucket> --> <unregister_bucket> --> <stop_task_group>
    --> <acquire tMutex> --> .. --> <cancel DcpBackfill> -->
    --> <destroy DcpBackfill> --> <destroy DcpProducer>
    --> <cancel Checkpoint creator task> --> [tries to acquire tMutex]

The fix here would be to not attempt to kill the task within
the DcpProducer's destructor, but to do so when the producer is
being disconnected.

+ Unit test case that reproduces the hang.

Change-Id: Ia3c0597e3d8f85a1b40ef56e251e38339023b471
Reviewed-on: http://review.couchbase.org/62699
Well-Formed: buildbot <build@couchbase.com>
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Chiyoung Seo <chiyoung@couchbase.com>
src/connmap.cc
src/connmap.h
src/dcp-producer.cc
src/dcp-producer.h
src/ep_engine.cc
tests/ep_testsuite.cc
tests/module_tests/stream_test.cc