]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4328] handle IOService stop on server shutdown
authorRazvan Becheriu <razvan@isc.org>
Fri, 30 Jan 2026 18:19:04 +0000 (20:19 +0200)
committerRazvan Becheriu <razvan@isc.org>
Mon, 2 Feb 2026 15:23:59 +0000 (15:23 +0000)
src/bin/dhcp4/tests/http_control_socket_unittest.cc
src/bin/dhcp6/tests/http_control_socket_unittest.cc

index 4fcf27420fc4af7106bc2656a4ed460d79dee822..3c59b91f251f6ab3ee471179bca434aca0dc7a43 100644 (file)
@@ -97,10 +97,14 @@ public:
     /// @brief Pointer to the tested server object
     boost::shared_ptr<NakedControlledDhcpv4Srv> server_;
 
+    /// @brief Flag which indicates if the server has stopped the IOService and
+    /// the client needs to handle it's own IO events.
+    bool handle_stop_;
+
     /// @brief Default constructor
     ///
     /// Sets socket path to its default value.
-    BaseCtrlChannelDhcpv4Test() : interfaces_("\"*\"") {
+    BaseCtrlChannelDhcpv4Test() : interfaces_("\"*\""), handle_stop_(false) {
         reset();
         IfaceMgr::instance().setTestMode(false);
         IfaceMgr::instance().setDetectCallback(std::bind(&IfaceMgr::checkDetectIfaces,
@@ -173,10 +177,24 @@ public:
         try {
             io_service->run();
         } catch (const std::exception& ex) {
+            handle_stop_ = false;
             ADD_FAILURE() << "Exception thrown while running test. Error: " << ex.what();
         } catch (...) {
+            handle_stop_ = false;
             ADD_FAILURE() << "Unknown exception thrown while running test.";
         }
+        if (handle_stop_) {
+            if (io_service->stopped()) {
+                io_service->restart();
+            }
+            try {
+                io_service->run();
+            } catch (const std::exception& ex) {
+                ADD_FAILURE() << "Exception thrown while running test (client IO). Error: " << ex.what();
+            } catch (...) {
+                ADD_FAILURE() << "Unknown exception thrown while running test (client IO).";
+            }
+        }
         test_timer.cancel();
         if (io_service->stopped()) {
             io_service->restart();
@@ -891,6 +909,7 @@ TEST_F(HttpsCtrlChannelDhcpv4Test, controlChannelNegative) {
 // via ControlChannel.
 void
 BaseCtrlChannelDhcpv4Test::testControlChannelShutdown() {
+    handle_stop_ = true;
     createHttpChannelServer();
     std::string response;
 
index 0d51f939dba192cef919aea0fca6b6a3bf997323..03e3480d53821d3034e1788e7ea172cd5ea41370 100644 (file)
@@ -133,10 +133,14 @@ public:
     /// @brief Pointer to the tested server object
     boost::shared_ptr<NakedControlledDhcpv6Srv> server_;
 
+    /// @brief Flag which indicates if the server has stopped the IOService and
+    /// the client needs to handle it's own IO events.
+    bool handle_stop_;
+
     /// @brief Default constructor
     ///
     /// Sets socket path to its default value.
-    BaseCtrlChannelDhcpv6Test() : interfaces_("\"*\"") {
+    BaseCtrlChannelDhcpv6Test() : interfaces_("\"*\""), handle_stop_(false) {
         reset();
         IfaceMgr::instance().setTestMode(false);
         IfaceMgr::instance().setDetectCallback(std::bind(&IfaceMgr::checkDetectIfaces,
@@ -193,10 +197,24 @@ public:
         try {
             io_service->run();
         } catch (const std::exception& ex) {
+            handle_stop_ = false;
             ADD_FAILURE() << "Exception thrown while running test. Error: " << ex.what();
         } catch (...) {
+            handle_stop_ = false;
             ADD_FAILURE() << "Unknown exception thrown while running test.";
         }
+        if (handle_stop_) {
+            if (io_service->stopped()) {
+                io_service->restart();
+            }
+            try {
+                io_service->run();
+            } catch (const std::exception& ex) {
+                ADD_FAILURE() << "Exception thrown while running test (client IO). Error: " << ex.what();
+            } catch (...) {
+                ADD_FAILURE() << "Unknown exception thrown while running test (client IO).";
+            }
+        }
         test_timer.cancel();
         if (io_service->stopped()) {
             io_service->restart();
@@ -900,6 +918,7 @@ TEST_F(HttpsCtrlChannelDhcpv6Test, controlChannelNegative) {
 // via ControlChannel.
 void
 BaseCtrlChannelDhcpv6Test::testControlChannelShutdown() {
+    handle_stop_ = true;
     createHttpChannelServer();
     std::string response;