diff --git a/nav2_ros_common/include/nav2_ros_common/service_client.hpp b/nav2_ros_common/include/nav2_ros_common/service_client.hpp index c1bc2bd8435..1cf32f25fe0 100644 --- a/nav2_ros_common/include/nav2_ros_common/service_client.hpp +++ b/nav2_ros_common/include/nav2_ros_common/service_client.hpp @@ -218,6 +218,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_; rclcpp::Clock::SharedPtr clock_; diff --git a/nav2_util/include/nav2_util/lifecycle_service_client.hpp b/nav2_util/include/nav2_util/lifecycle_service_client.hpp index 64860f47e87..56eea6b5ccd 100644 --- a/nav2_util/include/nav2_util/lifecycle_service_client.hpp +++ b/nav2_util/include/nav2_util/lifecycle_service_client.hpp @@ -57,6 +57,12 @@ class LifecycleServiceClient } } + ~LifecycleServiceClient() + { + change_state_.stop(); + get_state_.stop(); + } + /// Trigger a state change /** * Throws std::runtime_error on failure