From: Dave Watson Date: Mon, 8 Jun 2015 16:32:05 +0000 (-0700) Subject: Fix haystack threading crashes X-Git-Tag: v0.45.0~10 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c768c3f46991ce01f0fb06b3e070d8cbf8b25884;p=folly.git 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 --- diff --git a/folly/wangle/concurrent/IOThreadPoolExecutor.cpp b/folly/wangle/concurrent/IOThreadPoolExecutor.cpp index f8a68e25..7552cad9 100644 --- a/folly/wangle/concurrent/IOThreadPoolExecutor.cpp +++ b/folly/wangle/concurrent/IOThreadPoolExecutor.cpp @@ -156,6 +156,9 @@ void IOThreadPoolExecutor::threadRun(ThreadPtr thread) { } } stoppedThreads_.add(ioThread); + + ioThread->eventBase = nullptr; + eventBaseManager_->clearEventBase(); } // threadListLock_ is writelocked