Memory leak in BackfillManager due to circular dependancy with DcpProducer

Description

From Jim Walker:

The DcpProducer cannot be deleted because its deletion is performed via a smart pointer, but the DcpProducer in 4.0 is effectively
holding a reference to itself.

http://src.couchbase.org/source/xref/sherlock/ep-engine/src/dcp-producer.cc#80

That line of code passes “this" to BackfillManager and stored inside the manager as a smart pointer. By line 81 the DcpProducer has a reference of 1
and thus can never be deleted via the smart pointer cleanup we rely upon.

The leak though we are exposed to means that a DCP connection that is terminated will leak a DcpProducer object which I’ve calculated to be
less than 400 bytes.

This leak will be for every terminated DCP producer, be clean terminate or a connection-reset.

Components

Affects versions

Fix versions

Labels

Environment

None

Link to Log File, atop/blg, CBCollectInfo, Core dump

None

Release Notes Description

None

Activity

Show:

Jim Walker February 11, 2016 at 9:24 AM

This is in sherlock and master branches

Jim Walker December 4, 2015 at 10:31 AM

The lock acquisition in the destructors just needs wiping out. It protects nothing

Dave Rigby December 3, 2015 at 1:40 PM

Jim - do you want to take a look at this, given it's related to the original bug?

(If not assign back to me and I'll look at next week.)

Dave Rigby December 2, 2015 at 6:29 PM

Unfortunately, the "basic" fix for this (see linked Gerrit patch) highlights a latent lock order inversion (deadlock) in the destruction of BackfillManager. See the below ThreadSantizer report (from http://factory.couchbase.com/job/ep-engine-threadsanitizer-master/932/console):

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Is this a Regression?

Yes

Triage

Untriaged

Priority

Instabug

Open Instabug

PagerDuty

Sentry

Zendesk Support

Created December 2, 2015 at 4:27 PM
Updated February 11, 2016 at 9:24 AM
Resolved February 11, 2016 at 9:24 AM
Instabug