From c3bcac6717b5bf1b272c395d7be14a56cad8a829 Mon Sep 17 00:00:00 2001 From: Cedric Pradalier Date: Fri, 12 Sep 2025 22:43:28 +0200 Subject: [PATCH 1/5] Fixed the unloading severe warning by adding a shutdown function in network_bridge. Added try-catch in udp_bridge for a clean exit as well. --- include/network_bridge/network_bridge.hpp | 8 ++++++++ src/network_bridge.cpp | 22 +++++++++++++++------- src/network_interfaces/tcp_interface.cpp | 2 ++ src/network_interfaces/udp_interface.cpp | 6 +++++- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/include/network_bridge/network_bridge.hpp b/include/network_bridge/network_bridge.hpp index 5073c18..b9741b0 100644 --- a/include/network_bridge/network_bridge.hpp +++ b/include/network_bridge/network_bridge.hpp @@ -64,6 +64,14 @@ class NetworkBridge : public rclcpp::Node */ virtual void initialize(); + /** + * @brief Destroy the objects created by the bridge + * + * It should be called once spinning is over, and before the shared pointer is reset, to + * make sure the garbage collector can run + */ + virtual void shutdown(); + protected: /** * @brief Loads default parameters and creates subsciption managers for each topic. diff --git a/src/network_bridge.cpp b/src/network_bridge.cpp index f86a406..dc765cc 100644 --- a/src/network_bridge.cpp +++ b/src/network_bridge.cpp @@ -43,13 +43,7 @@ NetworkBridge::NetworkBridge(const std::string & node_name) NetworkBridge::~NetworkBridge() { - network_interface_->close(); - network_interface_.reset(); - - network_check_timer_.reset(); - sub_mgrs_.clear(); - timers_.clear(); - publishers_.clear(); + shutdown(); } void NetworkBridge::initialize() @@ -59,6 +53,19 @@ void NetworkBridge::initialize() network_interface_->open(); } +void NetworkBridge::shutdown() +{ + if (network_interface_) { + network_interface_->close(); + } + network_interface_.reset(); + + network_check_timer_.reset(); + sub_mgrs_.clear(); + timers_.clear(); + publishers_.clear(); +} + void NetworkBridge::load_parameters() { this->declare_parameter( @@ -422,6 +429,7 @@ int main(int argc, char ** argv) node->initialize(); rclcpp::spin(node); + node->shutdown(); node.reset(); rclcpp::shutdown(); diff --git a/src/network_interfaces/tcp_interface.cpp b/src/network_interfaces/tcp_interface.cpp index a77bbbe..dd7c15f 100644 --- a/src/network_interfaces/tcp_interface.cpp +++ b/src/network_interfaces/tcp_interface.cpp @@ -102,11 +102,13 @@ void TcpInterface::close() try { packet_thread_.join(); } catch (std::system_error &) { + // the thread was not started } io_context_.stop(); try { io_thread_.join(); } catch (std::system_error &) { + // the thread was not started } } diff --git a/src/network_interfaces/udp_interface.cpp b/src/network_interfaces/udp_interface.cpp index 46a4659..7ee0e45 100644 --- a/src/network_interfaces/udp_interface.cpp +++ b/src/network_interfaces/udp_interface.cpp @@ -59,7 +59,11 @@ void UdpInterface::open() void UdpInterface::close() { io_context_.stop(); - io_thread_.join(); + try { + io_thread_.join(); + } catch (std::system_error&) { + // the thread was not started + } } void UdpInterface::load_parameters() From 0067d5cb01264f4cb07d70598e631b0dff530437 Mon Sep 17 00:00:00 2001 From: Cedric Pradalier Date: Fri, 12 Sep 2025 22:48:07 +0200 Subject: [PATCH 2/5] Applied uncrustify to force 2-space indents --- include/network_bridge/network_bridge.hpp | 2 +- src/network_bridge.cpp | 4 ++-- src/network_interfaces/udp_interface.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/network_bridge/network_bridge.hpp b/include/network_bridge/network_bridge.hpp index b9741b0..91efc82 100644 --- a/include/network_bridge/network_bridge.hpp +++ b/include/network_bridge/network_bridge.hpp @@ -67,7 +67,7 @@ class NetworkBridge : public rclcpp::Node /** * @brief Destroy the objects created by the bridge * - * It should be called once spinning is over, and before the shared pointer is reset, to + * It should be called once spinning is over, and before the shared pointer is reset, to * make sure the garbage collector can run */ virtual void shutdown(); diff --git a/src/network_bridge.cpp b/src/network_bridge.cpp index dc765cc..79d63dc 100644 --- a/src/network_bridge.cpp +++ b/src/network_bridge.cpp @@ -43,7 +43,7 @@ NetworkBridge::NetworkBridge(const std::string & node_name) NetworkBridge::~NetworkBridge() { - shutdown(); + shutdown(); } void NetworkBridge::initialize() @@ -53,7 +53,7 @@ void NetworkBridge::initialize() network_interface_->open(); } -void NetworkBridge::shutdown() +void NetworkBridge::shutdown() { if (network_interface_) { network_interface_->close(); diff --git a/src/network_interfaces/udp_interface.cpp b/src/network_interfaces/udp_interface.cpp index 7ee0e45..b2c97b1 100644 --- a/src/network_interfaces/udp_interface.cpp +++ b/src/network_interfaces/udp_interface.cpp @@ -60,8 +60,8 @@ void UdpInterface::close() { io_context_.stop(); try { - io_thread_.join(); - } catch (std::system_error&) { + io_thread_.join(); + } catch (std::system_error &) { // the thread was not started } } From 33592892538483acc5dd95310edab8ec6dbfca32 Mon Sep 17 00:00:00 2001 From: Ethan Brown <97919387+brow1633@users.noreply.github.com> Date: Fri, 12 Sep 2025 14:27:12 -0700 Subject: [PATCH 3/5] fix whitespace --- src/network_interfaces/tcp_interface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/network_interfaces/tcp_interface.cpp b/src/network_interfaces/tcp_interface.cpp index dd7c15f..b8e8313 100644 --- a/src/network_interfaces/tcp_interface.cpp +++ b/src/network_interfaces/tcp_interface.cpp @@ -102,13 +102,13 @@ void TcpInterface::close() try { packet_thread_.join(); } catch (std::system_error &) { - // the thread was not started + // the thread was not started } io_context_.stop(); try { io_thread_.join(); } catch (std::system_error &) { - // the thread was not started + // the thread was not started } } From 04d2adad3983ae08068731e43dfd5a079216f839 Mon Sep 17 00:00:00 2001 From: Cedric Pradalier Date: Fri, 12 Sep 2025 23:27:22 +0200 Subject: [PATCH 4/5] Another run of uncrustify --- src/network_interfaces/tcp_interface.cpp | 4 ++-- src/network_interfaces/udp_interface.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/network_interfaces/tcp_interface.cpp b/src/network_interfaces/tcp_interface.cpp index dd7c15f..ef9d4c8 100644 --- a/src/network_interfaces/tcp_interface.cpp +++ b/src/network_interfaces/tcp_interface.cpp @@ -102,13 +102,13 @@ void TcpInterface::close() try { packet_thread_.join(); } catch (std::system_error &) { - // the thread was not started + // the thread was not started } io_context_.stop(); try { io_thread_.join(); } catch (std::system_error &) { - // the thread was not started + // the thread was not started } } diff --git a/src/network_interfaces/udp_interface.cpp b/src/network_interfaces/udp_interface.cpp index b2c97b1..9b571d4 100644 --- a/src/network_interfaces/udp_interface.cpp +++ b/src/network_interfaces/udp_interface.cpp @@ -62,7 +62,7 @@ void UdpInterface::close() try { io_thread_.join(); } catch (std::system_error &) { - // the thread was not started + // the thread was not started } } From 0f88c1f88033b72349191bc595defa05e7bfe531 Mon Sep 17 00:00:00 2001 From: Ethan Brown <97919387+brow1633@users.noreply.github.com> Date: Fri, 12 Sep 2025 14:27:26 -0700 Subject: [PATCH 5/5] whitespace --- src/network_interfaces/udp_interface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network_interfaces/udp_interface.cpp b/src/network_interfaces/udp_interface.cpp index b2c97b1..41ba669 100644 --- a/src/network_interfaces/udp_interface.cpp +++ b/src/network_interfaces/udp_interface.cpp @@ -62,7 +62,7 @@ void UdpInterface::close() try { io_thread_.join(); } catch (std::system_error &) { - // the thread was not started + // the thread was not started } }