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