fix potential race/memory corruption in IOThreadPoolExecutor
authorJames Sedgwick <jsedgwick@fb.com>
Mon, 17 Nov 2014 23:04:35 +0000 (15:04 -0800)
committerDave Watson <davejwatson@fb.com>
Wed, 19 Nov 2014 20:52:32 +0000 (12:52 -0800)
commit0a14b4ccb443adbe283e8681e4e151b2eb20ceca
tree42f1b48a3dbc3703ea73a5978c254440aed0d3f8
parentfe22c76c53069bb4f1338a5fa6ffeb6a8a2a5923
fix potential race/memory corruption in IOThreadPoolExecutor

Summary:
In unusual but possible circumstances, the EventBase and thus pending tasks will outlive the pool, so we shouldn't keep references of any kind to the pool in the task.
The only reference we were keeping was used to access the task stats rx subject. Store the subject as a shared ptr and give a copy of the ptr to the Thread object, which is itself
owned by a shared ptr and captured by every task. I thought this had to do with the thread local leak in mentioned in the test plan of D1682860 but this patch doesn't actually fix that :(
Thankfully, while task surfing I saw @phillip's awesome D1682698. Patching that in fixes the leak! Woo. Either way, this is more correct.

Test Plan: unit under clang/asan

Reviewed By: davejwatson@fb.com

Subscribers: trunkagent, fugalh, njormrod, folly-diffs@, philipp

FB internal diff: D1683221

Tasks: 5336655

Signature: t1:1683221:1416264933:946d29b5a3eb22ed08812f2adefb7284b1899e4e
folly/experimental/wangle/concurrent/IOThreadPoolExecutor.cpp
folly/experimental/wangle/concurrent/IOThreadPoolExecutor.h
folly/experimental/wangle/concurrent/ThreadPoolExecutor.cpp
folly/experimental/wangle/concurrent/ThreadPoolExecutor.h