Skip to content

Commit

Permalink
LifecycleNode shutdown on dtor only with valid context. (#2545)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya committed May 30, 2024
1 parent 0e12a7b commit 9d9710a
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions rclcpp_lifecycle/src/lifecycle_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,23 @@ LifecycleNode::~LifecycleNode()
auto current_state = LifecycleNode::get_current_state().id();
// shutdown if necessary to avoid leaving the device in any other primary state
if (current_state < lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED) {
auto ret = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::ERROR;
auto finalized = LifecycleNode::shutdown(ret);
if (finalized.id() != lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED ||
ret != rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS)
{
RCLCPP_WARN(
if (node_base_->get_context()->is_valid()) {
auto ret = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::ERROR;
auto finalized = LifecycleNode::shutdown(ret);
if (finalized.id() != lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED ||
ret != rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS)
{
RCLCPP_WARN(
rclcpp::get_logger("rclcpp_lifecycle"),
"Shutdown error in destruction of LifecycleNode: final state(%s)",
finalized.label().c_str());
}
} else {
// TODO(fujitatomoya): consider when context is gracefully shutdown before.
RCLCPP_DEBUG(
rclcpp::get_logger("rclcpp_lifecycle"),
"Shutdown error in destruction of LifecycleNode: final state(%s)",
finalized.label().c_str());
"Context invalid error in destruction of LifecycleNode: Node still in transition state(%u)",
current_state);
}
} else if (current_state > lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED) {
RCLCPP_WARN(
Expand All @@ -174,6 +182,7 @@ LifecycleNode::~LifecycleNode()

// release sub-interfaces in an order that allows them to consult with node_base during tear-down
node_waitables_.reset();
node_type_descriptions_.reset();
node_time_source_.reset();
node_parameters_.reset();
node_clock_.reset();
Expand All @@ -182,6 +191,7 @@ LifecycleNode::~LifecycleNode()
node_timers_.reset();
node_logging_.reset();
node_graph_.reset();
node_base_.reset();
}

const char *
Expand Down

0 comments on commit 9d9710a

Please sign in to comment.