Browse Source

[3971] Catch exceptions in the CtrlDhcp{4,6}Srv destructors.

Marcin Siodelski 9 years ago
parent
commit
439e44ae0d
2 changed files with 46 additions and 32 deletions
  1. 23 16
      src/bin/dhcp4/ctrl_dhcp4_srv.cc
  2. 23 16
      src/bin/dhcp6/ctrl_dhcp6_srv.cc

+ 23 - 16
src/bin/dhcp4/ctrl_dhcp4_srv.cc

@@ -226,22 +226,29 @@ void ControlledDhcpv4Srv::shutdown() {
 }
 
 ControlledDhcpv4Srv::~ControlledDhcpv4Srv() {
-    cleanup();
-
-    // Stop worker thread running timers, if it is running.
-    timer_mgr_->stopThread();
-
-    // Close the command socket (if it exists).
-    CommandMgr::instance().closeCommandSocket();
-
-    // Deregister any registered commands
-    CommandMgr::instance().deregisterCommand("shutdown");
-    CommandMgr::instance().deregisterCommand("statistic-get");
-    CommandMgr::instance().deregisterCommand("statistic-reset");
-    CommandMgr::instance().deregisterCommand("statistic-remove");
-    CommandMgr::instance().deregisterCommand("statistic-get-all");
-    CommandMgr::instance().deregisterCommand("statistic-reset-all");
-    CommandMgr::instance().deregisterCommand("statistic-remove-all");
+    try {
+        cleanup();
+
+        // Stop worker thread running timers, if it is running.
+        timer_mgr_->stopThread();
+
+        // Close the command socket (if it exists).
+        CommandMgr::instance().closeCommandSocket();
+
+        // Deregister any registered commands
+        CommandMgr::instance().deregisterCommand("shutdown");
+        CommandMgr::instance().deregisterCommand("statistic-get");
+        CommandMgr::instance().deregisterCommand("statistic-reset");
+        CommandMgr::instance().deregisterCommand("statistic-remove");
+        CommandMgr::instance().deregisterCommand("statistic-get-all");
+        CommandMgr::instance().deregisterCommand("statistic-reset-all");
+        CommandMgr::instance().deregisterCommand("statistic-remove-all");
+
+    } catch (...) {
+        // Don't want to throw exceptions from the destructor. The server
+        // is shutting down anyway.
+        ;
+    }
 
     server_ = NULL; // forget this instance. Noone should call any handlers at
                     // this stage.

+ 23 - 16
src/bin/dhcp6/ctrl_dhcp6_srv.cc

@@ -222,22 +222,29 @@ void ControlledDhcpv6Srv::shutdown() {
 }
 
 ControlledDhcpv6Srv::~ControlledDhcpv6Srv() {
-    cleanup();
-
-    // Stop worker thread running timers, if it is running.
-    timer_mgr_->stopThread();
-
-   // Close the command socket (if it exists).
-    CommandMgr::instance().closeCommandSocket();
-
-    // Deregister any registered commands
-    CommandMgr::instance().deregisterCommand("shutdown");
-    CommandMgr::instance().deregisterCommand("statistic-get");
-    CommandMgr::instance().deregisterCommand("statistic-reset");
-    CommandMgr::instance().deregisterCommand("statistic-remove");
-    CommandMgr::instance().deregisterCommand("statistic-get-all");
-    CommandMgr::instance().deregisterCommand("statistic-reset-all");
-    CommandMgr::instance().deregisterCommand("statistic-remove-all");
+    try {
+        cleanup();
+
+        // Stop worker thread running timers, if it is running.
+        timer_mgr_->stopThread();
+
+        // Close the command socket (if it exists).
+        CommandMgr::instance().closeCommandSocket();
+
+        // Deregister any registered commands
+        CommandMgr::instance().deregisterCommand("shutdown");
+        CommandMgr::instance().deregisterCommand("statistic-get");
+        CommandMgr::instance().deregisterCommand("statistic-reset");
+        CommandMgr::instance().deregisterCommand("statistic-remove");
+        CommandMgr::instance().deregisterCommand("statistic-get-all");
+        CommandMgr::instance().deregisterCommand("statistic-reset-all");
+        CommandMgr::instance().deregisterCommand("statistic-remove-all");
+
+    } catch (...) {
+        // Don't want to throw exceptions from the destructor. The server
+        // is shutting down anyway.
+        ;
+    }
 
     server_ = NULL; // forget this instance. There should be no callback anymore
                     // at this stage anyway.