From: Razvan Becheriu Date: Fri, 30 Jan 2026 18:19:04 +0000 (+0200) Subject: [#4328] handle IOService stop on server shutdown X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51a6f23be4e1a5419416cc12e1b113ffeabc24fb;p=thirdparty%2Fkea.git [#4328] handle IOService stop on server shutdown --- diff --git a/src/bin/dhcp4/tests/http_control_socket_unittest.cc b/src/bin/dhcp4/tests/http_control_socket_unittest.cc index 4fcf27420f..3c59b91f25 100644 --- a/src/bin/dhcp4/tests/http_control_socket_unittest.cc +++ b/src/bin/dhcp4/tests/http_control_socket_unittest.cc @@ -97,10 +97,14 @@ public: /// @brief Pointer to the tested server object boost::shared_ptr 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; diff --git a/src/bin/dhcp6/tests/http_control_socket_unittest.cc b/src/bin/dhcp6/tests/http_control_socket_unittest.cc index 0d51f939db..03e3480d53 100644 --- a/src/bin/dhcp6/tests/http_control_socket_unittest.cc +++ b/src/bin/dhcp6/tests/http_control_socket_unittest.cc @@ -133,10 +133,14 @@ public: /// @brief Pointer to the tested server object boost::shared_ptr 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;