Fix haystack threading crashes
authorDave Watson <davejwatson@fb.com>
Mon, 8 Jun 2015 16:32:05 +0000 (09:32 -0700)
committerSara Golemon <sgolemon@fb.com>
Tue, 9 Jun 2015 20:20:22 +0000 (13:20 -0700)
commitc768c3f46991ce01f0fb06b3e070d8cbf8b25884
tree73499f45e402d413cbbc72347e2b7fd9afad3258
parentf406269abf94a83f2a3b941ad844664deb94b48d
Fix haystack threading crashes

Summary:
proxygen/facebook/httpserver/filter/StatsFilter expects the threadlocal stats_ variable to be initialized before any requests, and destroyed on the same thread.

There were two issues:
1) addObserver was being called after bind(), so it was possible to get some requests before the stats_ variable was initialized.  Moved up the observer, should fix it (although I don't have a repro for this)

2) on server stop(), sometimes the observer onServerStop() callback was called, but the eventBase had already stopped.  The IOThreadPoolExecutor eventually deleted the eventBase, causing consumeUntilDrained to be called, but in the main thread, and not in the eventBase's thread.  I'm not as sure about this fix, hopefully @jsedgwick can chime in: I explicitly deleted the eventBase on the eventBase thread before join.  Here's the stack for this issue:

P19866015

Reviewed By: shiva@fb.com

Subscribers: doug, fugalh, bmatheny, folly-diffs@, yfeldblum, chalfant, shiva, jsedgwick

FB internal diff: D2132208

Signature: t1:2132208:1433537787:4379ba50a908ca6f19924c2339876afaf663364c
folly/wangle/concurrent/IOThreadPoolExecutor.cpp