Skip to content

Commit 2f451b6

Browse files
committed
lifecycle node dtor shutdown should be called only in primary state.
Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
1 parent dd24285 commit 2f451b6

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

rclcpp_lifecycle/src/lifecycle_node.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,9 @@ LifecycleNode::LifecycleNode(
152152

153153
LifecycleNode::~LifecycleNode()
154154
{
155-
// shutdown if necessary to avoid leaving the device in unknown state
156-
if (LifecycleNode::get_current_state().id() !=
157-
lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED)
158-
{
155+
auto current_state = LifecycleNode::get_current_state().id();
156+
// shutdown if necessary to avoid leaving the device in any other primary state
157+
if (current_state < lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED) {
159158
auto ret = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::ERROR;
160159
auto finalized = LifecycleNode::shutdown(ret);
161160
if (finalized.id() != lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED ||
@@ -166,6 +165,11 @@ LifecycleNode::~LifecycleNode()
166165
"Shutdown error in destruction of LifecycleNode: final state(%s)",
167166
finalized.label().c_str());
168167
}
168+
} else if (current_state > lifecycle_msgs::msg::State::PRIMARY_STATE_FINALIZED) {
169+
RCLCPP_WARN(
170+
rclcpp::get_logger("rclcpp_lifecycle"),
171+
"Cannot shutdown the LifecycleNode in transition state(%u)",
172+
current_state);
169173
}
170174

171175
// release sub-interfaces in an order that allows them to consult with node_base during tear-down

0 commit comments

Comments
 (0)