waitFor race workaround
authorHans Fugal <fugalh@fb.com>
Tue, 21 Oct 2014 18:55:52 +0000 (11:55 -0700)
committerdcsommer <dcsommer@fb.com>
Wed, 29 Oct 2014 23:03:21 +0000 (16:03 -0700)
Summary: Fixing the race will take some more thought. Probably a condvar. For now, I'm turning waitFor into a spinlock instead.

Test Plan: new unit test that deadlocks before the workaround

Reviewed By: jsedgwick@fb.com

Subscribers: trunkagent, net-systems@, fugalh, exa, njormrod, folly-diffs@

FB internal diff: D1628015

Tasks: 5427828

folly/wangle/ManualExecutor.h
folly/wangle/test/ExecutorTest.cpp

index 27caf28cc7ed95eabe348a550f4610f4ddc24089..329f9fc65b42fda178c7675cc5e9110aaf922ca7 100644 (file)
@@ -56,8 +56,16 @@ namespace folly { namespace wangle {
 
     /// makeProgress until this Future is ready.
     template <class F> void waitFor(F const& f) {
+      // TODO(5427828)
+#if 0
       while (!f.isReady())
         makeProgress();
+#else
+      while (!f.isReady()) {
+        run();
+      }
+#endif
+
     }
 
     virtual void scheduleAt(Func&& f, TimePoint const& t) override {
index 1e60ab0b20515f2890c22005f9ddc5e2c2f833e8..b4ec76847771206352f45beb8ac5c9fb1f9a7097 100644 (file)
@@ -18,6 +18,8 @@
 #include <folly/wangle/InlineExecutor.h>
 #include <folly/wangle/ManualExecutor.h>
 #include <folly/wangle/QueuedImmediateExecutor.h>
+#include <folly/wangle/Future.h>
+#include <folly/Baton.h>
 
 using namespace folly::wangle;
 using namespace std::chrono;
@@ -89,6 +91,22 @@ TEST(ManualExecutor, advanceNeg) {
   EXPECT_EQ(count, 0);
 }
 
+TEST(ManualExecutor, waitForDoesNotDeadlock) {
+  ManualExecutor east, west;
+  folly::Baton<> baton;
+  auto f = makeFuture()
+    .via(&east)
+    .then([](Try<void>){ return makeFuture(); })
+    .via(&west);
+  std::thread t([&]{
+    baton.post();
+    west.waitFor(f);
+  });
+  baton.wait();
+  east.run();
+  t.join();
+}
+
 TEST(Executor, InlineExecutor) {
   InlineExecutor x;
   size_t counter = 0;