diff --git a/nav2_util/include/nav2_util/lifecycle_service_client.hpp b/nav2_util/include/nav2_util/lifecycle_service_client.hpp index 341a7706b3f..4b56fd131a3 100644 --- a/nav2_util/include/nav2_util/lifecycle_service_client.hpp +++ b/nav2_util/include/nav2_util/lifecycle_service_client.hpp @@ -38,6 +38,12 @@ class LifecycleServiceClient const std::string & lifecycle_node_name, rclcpp::Node::SharedPtr parent_node); + ~LifecycleServiceClient() + { + change_state_.stop(); + get_state_.stop(); + } + /// Trigger a state change /** * Throws std::runtime_error on failure diff --git a/nav2_util/include/nav2_util/service_client.hpp b/nav2_util/include/nav2_util/service_client.hpp index 5d8ffcbe99b..97bb16d852e 100644 --- a/nav2_util/include/nav2_util/service_client.hpp +++ b/nav2_util/include/nav2_util/service_client.hpp @@ -204,6 +204,16 @@ class ServiceClient return service_name_; } + /** + * @brief Stop any running spin operations on the internal executor + */ + void stop() + { + if (client_) { + callback_group_executor_->cancel(); + } + } + protected: std::string service_name_; NodeT node_;