Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on_shutdown callback of controllers never get executed #1987

Closed
christophfroehlich opened this issue Jan 7, 2025 · 3 comments · Fixed by #1995
Closed

on_shutdown callback of controllers never get executed #1987

christophfroehlich opened this issue Jan 7, 2025 · 3 comments · Fixed by #1995
Labels

Comments

@christophfroehlich
Copy link
Contributor

After #1979 there is still one remaining problem:
The on_shutdown callback never gets executed, because the derived class is destroyed before the controller_interface_base. Moving that to controller_interface does not help, controllers are still derived from that.
For me it seems that even the controller_manager never calls the shutdown transition explicitly for controllers? So we never trigger that transition from any controller, and every on_shutdown override just never gets executed. (resource manager does that for hardware components).

Maybe we just need to trigger shutdown instead of cleanup here:

try
{
const auto new_state = controller.c->get_node()->cleanup();
if (new_state.id() != lifecycle_msgs::msg::State::PRIMARY_STATE_UNCONFIGURED)
{
RCLCPP_WARN(
get_logger(), "Failed to clean-up the controller '%s' before unloading!",
controller_name.c_str());
}
}
catch (const std::exception & e)
{
RCLCPP_ERROR(
get_logger(),
"Caught exception of type : %s while cleaning up the controller '%s' before unloading: %s",
typeid(e).name(), controller_name.c_str(), e.what());
}
catch (...)
{
RCLCPP_ERROR(
get_logger(), "Failed to clean-up the controller '%s' before unloading",
controller_name.c_str());
}
}

@Wiktor-99
Copy link
Contributor

Hi,

Referring to the ROS 2 design (Manged node).

Transition State: ShuttingDown:

In this transition state the callback onShutdown will be executed. This method is expected to do any cleanup necessary before destruction. It may be entered from any Primary State except Finalized, the originating state will be passed to the method.

So if we are going to destruct the node it seems that the shutdown method should be called instead of cleanup.

@christophfroehlich
Copy link
Contributor Author

Exactly, before unloading it should be in finalized state, i.e. we should call the shutdown transition which is valid from active, inactive, and unconfigured state. @Wiktor-99 do you want to fix that?

@Wiktor-99
Copy link
Contributor

Yep, I'll do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants