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)
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

index f8a68e25115d1a95ece7d75c670c497a1215b0b5..7552cad93ced27e8b7ed33d804976baae5239c4a 100644 (file)
@@ -156,6 +156,9 @@ void IOThreadPoolExecutor::threadRun(ThreadPtr thread) {
     }
   }
   stoppedThreads_.add(ioThread);
+
+  ioThread->eventBase = nullptr;
+  eventBaseManager_->clearEventBase();
 }
 
 // threadListLock_ is writelocked