Get rid of try/catch in messageAvailable, which is now noexcept
authorAlan Frindell <afrind@fb.com>
Thu, 6 Apr 2017 21:00:58 +0000 (14:00 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 6 Apr 2017 21:06:34 +0000 (14:06 -0700)
Summary: The problem with catching the exception here is stack information is lost.  Just let it std::terminate if it throws

Reviewed By: ikobzar

Differential Revision: D4831909

fbshipit-source-id: 42139bd7caee0fedff13328d52fa3be1c517e730

folly/io/async/EventBase.cpp
folly/io/async/test/EventBaseTest.cpp

index 895e1a4959b2afb16728783c60f55fdb63d89578..8d6c03f211d0c2ddad2a95def05e1152b99ac6ff 100644 (file)
@@ -54,21 +54,7 @@ class EventBase::FunctionRunner
       // wake up the loop.  We can ignore these messages.
       return;
     }
-
-    // The function should never throw an exception, because we have no
-    // way of knowing what sort of error handling to perform.
-    //
-    // If it does throw, log a message and abort the program.
-    try {
-      msg();
-    } catch (const std::exception& ex) {
-      LOG(ERROR) << "runInEventBaseThread() function threw a "
-                 << typeid(ex).name() << " exception: " << ex.what();
-      abort();
-    } catch (...) {
-      LOG(ERROR) << "runInEventBaseThread() function threw an exception";
-      abort();
-    }
+    msg();
   }
 };
 
index 01157f916da0f6a0a2b79a6ff70ebedd7bfe9ef9..ae455c7eb613ecb63a506a4dfbe5b049131a3c01 100644 (file)
@@ -1351,6 +1351,21 @@ TEST(EventBaseTest, RunInLoopStopLoop) {
   ASSERT_LE(c1.getCount(), 11);
 }
 
+TEST(EventBaseTest, messageAvailableException) {
+  auto deadManWalking = [] {
+    EventBase eventBase;
+    std::thread t([&] {
+      // Call this from another thread to force use of NotificationQueue in
+      // runInEventBaseThread
+      eventBase.runInEventBaseThread(
+          []() { throw std::runtime_error("boom"); });
+    });
+    t.join();
+    eventBase.loopForever();
+  };
+  EXPECT_DEATH(deadManWalking(), ".*");
+}
+
 TEST(EventBaseTest, TryRunningAfterTerminate) {
   EventBase eventBase;
   CountedLoopCallback c1(&eventBase, 1,