From 0a48fa4df5593035f7b0fb82eef9137c9de8833b Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Mon, 11 Aug 2025 17:49:46 +0000 Subject: [PATCH 1/2] Fix lifecycle manager deadlock during shutdown Add stop() method to ServiceClient that cancels internal executor operations and call it in LifecycleServiceClient destructor to prevent deadlock when CTRL+C is pressed during lifecycle node bringup. This addresses issue #5437 where spin_until_future_complete can hang indefinitely during shutdown when bringup and shutdown sequences run concurrently. Co-authored-by: Steve Macenski --- .../include/nav2_ros_common/service_client.hpp | 10 ++++++++++ .../include/nav2_util/lifecycle_service_client.hpp | 6 ++++++ 2 files changed, 16 insertions(+) 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..f57537aad82 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 From 913840f230abde552b780a4a8cc55137e8090b2c Mon Sep 17 00:00:00 2001 From: Steve Macenski Date: Mon, 11 Aug 2025 10:53:05 -0700 Subject: [PATCH 2/2] Update service_client.hpp Signed-off-by: Steve Macenski --- nav2_ros_common/include/nav2_ros_common/service_client.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f57537aad82..1cf32f25fe0 100644 --- a/nav2_ros_common/include/nav2_ros_common/service_client.hpp +++ b/nav2_ros_common/include/nav2_ros_common/service_client.hpp @@ -224,7 +224,7 @@ class ServiceClient void stop() { if (client_) { - callback_group_executor_.cancel(); + callback_group_executor_->cancel(); } }