Fix: Drop exception thrown from async callback 79/33779/3
authorMateusz Malicki <m.malicki2@samsung.com>
Wed, 14 Jan 2015 14:28:01 +0000 (15:28 +0100)
committerMateusz Malicki <m.malicki2@samsung.com>
Thu, 15 Jan 2015 12:04:55 +0000 (13:04 +0100)
[Bug/Feature]   Crash when exception are thrown from async callback
[Cause]         Exception from async callback
[Solution]      Drop exception
[Verification]  Build, install, run test on slp

Change-Id: I00fad962beb488508d25a21a68ee7e487f317ba0

tests/unit_tests/server/ut-zones-manager.cpp

index a733e05..5b29340 100644 (file)
@@ -42,6 +42,7 @@
 #include "utils/fs.hpp"
 #include "utils/img.hpp"
 #include "utils/scoped-dir.hpp"
+#include "logger/logger.hpp"
 
 #include <vector>
 #include <map>
@@ -79,6 +80,22 @@ const std::string FILE_CONTENT = "File content\n"
 const std::string NON_EXISTANT_ZONE_ID = "NON_EXISTANT_ZONE_ID";
 const std::string ZONES_PATH = "/tmp/ut-zones"; // the same as in daemon.conf
 
+/**
+ * Currently there is no way to propagate an error from async call
+ * dropException are used to prevent system crash
+ **/
+DbusConnection::AsyncMethodCallCallback
+dropException(const DbusConnection::AsyncMethodCallCallback& fun)
+{
+    return [fun](dbus::AsyncMethodCallResult& arg) -> void {
+        try {
+            fun(arg);
+        } catch (const std::exception& ex) {
+            LOGE("Got exception: " << ex.what());
+        }
+    };
+}
+
 class DbusAccessory {
 public:
     static const int HOST_ID = 0;
@@ -326,7 +343,7 @@ public:
                                  api::host::METHOD_CREATE_ZONE,
                                  parameters,
                                  "()",
-                                 asyncResult);
+                                 dropException(asyncResult));
     }
 
     void callAsyncMethodDestroyZone(const std::string& id,
@@ -346,7 +363,7 @@ public:
                                  api::host::METHOD_DESTROY_ZONE,
                                  parameters,
                                  "()",
-                                 asyncResult);
+                                 dropException(asyncResult));
     }
 
     void callAsyncMethodShutdownZone(const std::string& id,
@@ -366,7 +383,7 @@ public:
                                  api::host::METHOD_SHUTDOWN_ZONE,
                                  parameters,
                                  "()",
-                                 asyncResult);
+                                 dropException(asyncResult));
     }
 
     void callAsyncMethodStartZone(const std::string& id,
@@ -386,7 +403,7 @@ public:
                                  api::host::METHOD_START_ZONE,
                                  parameters,
                                  "()",
-                                 asyncResult);
+                                 dropException(asyncResult));
     }
 
     void callMethodLockZone(const std::string& id)
@@ -576,8 +593,8 @@ BOOST_AUTO_TEST_CASE(NotifyActiveZoneTest)
         dbus.second->callMethodNotify();
     }
 
-    BOOST_CHECK(signalReceivedLatch.waitForN(dbuses.size() - 1u, EVENT_TIMEOUT));
-    BOOST_CHECK(signalReceivedLatch.empty());
+    BOOST_REQUIRE(signalReceivedLatch.waitForN(dbuses.size() - 1u, EVENT_TIMEOUT));
+    BOOST_REQUIRE(signalReceivedLatch.empty());
 
     //check if there are no signals that was received more than once
     for (const auto& source : signalReceivedSourcesMap[1]) {
@@ -718,8 +735,8 @@ BOOST_AUTO_TEST_CASE(MoveFileTest)
 
     BOOST_CHECK_EQUAL(dbuses.at(1)->callMethodMove(ZONE2, TMP + "/file"),
                       api::zone::FILE_MOVE_SUCCEEDED);
-    BOOST_CHECK(notificationLatch.wait(EVENT_TIMEOUT));
-    BOOST_CHECK(notificationLatch.empty());
+    BOOST_REQUIRE(notificationLatch.wait(EVENT_TIMEOUT));
+    BOOST_REQUIRE(notificationLatch.empty());
     BOOST_CHECK_EQUAL(notificationSource, ZONE1);
     BOOST_CHECK_EQUAL(notificationPath, TMP + "/file");
     BOOST_CHECK_EQUAL(notificationRetcode, api::zone::FILE_MOVE_SUCCEEDED);