-
Notifications
You must be signed in to change notification settings - Fork 417
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
rclcpp::spin_some throws exception after SIGINT #1066
Comments
i can reproduce the issue, https://github.com/fujitatomoya/examples/tree/topic-20200417-exception-after-sigin-1066 |
since Executor possibly throws exception, |
Well, one could do something along those lines: try {
// ...
while (rclcpp::ok())
{
std::this_thread::sleep_for(std::chrono::seconds(1));
rclcpp::spin_some(ros_node);
}
} catch (rclcpp::exceptions::RCLError &e) {
if (rclcpp::ok()) {
// handle the exception / report to user
} else {
// ignore, ROS is shutting down
}
} However, it feels a bit wrong as exceptions should only be thrown in exceptional situations - and an orderly shutdown should not be among them. @fujitatomoya Thanks for setting up the running example! |
Since allowing to throw exception inside constructor of Executor and spin_some() doesn't return any value(such as error number), I guess author hope user handle the exception. So this issue isn't a bug. |
I do not think this is a bug either, i guess that user application needs to take care of that exception. which means that i guess we should close this issue and make issue on https://github.com/ros2/examples. |
It's definitely not a bug, but as I said above, it feels wrong when an orderly shutdown throws an exception. To avoid this behaviour, I'm using the following code now: rclcpp::executors::SingleThreadedExecutor ros_executor;
while (rclcpp::ok())
{
std::this_thread::sleep_for(std::chrono::seconds(1));
ros_executor.spin_node_some(ros_node);
} I would recommend to use this in the example. |
Yes. It is better to discuss in https://github.com/ros2/examples/issues. |
If receive SIGINT before "rclcpp::executors::SingleThreadedExecutor ros_executor;", exception also will be thrown. Besides, the purpose of example is to guide user how to do. I think author doesn't suggest user writing codes as above way. Otherwise rclcpp::spin_some() is useless. Anyway, we can create an issue to discuss in https://github.com/ros2/examples/issues and listen to other' opinions. What do you think ? |
Yes, I agree that we should discuss it in ros2/examples. Will close this now in favour of ros2/examples#266. |
Fixes #458. An exception can be thrown if an interrupt occurs between checking rclcpp::ok() and rclcpp::spin_some(). Related to ros2/rclcpp#1066 Signed-off-by: Jacob Perron <[email protected]>
Fixes #458. An exception can be thrown if an interrupt occurs between checking rclcpp::ok() and rclcpp::spin_some(). Related to ros2/rclcpp#1066 Signed-off-by: Jacob Perron <[email protected]>
Bug report
Required Info:
Steps to reproduce issue
There are many examples, for instance the minimal publisher example, which call
rclcpp::spin_some
in a while loop that checksrclcpp::ok()
.However, if the program receives a SIGINT between those two calls, the context might become invalid and
spin_some
throws an exception:An easy way to reproduce this behaviour is:
Expected behavior
I can think of several options:
spin_some
in a try-catch block.spin_some
not fail under this condition.spin_some
atomic, such that it both checks and spins.Usage could be:
while (rclcpp::spin_some(node)) {}
rclcpp::ok()
would still signal that the program should end. This might be related to Executor does not maintain a reference to nodes #726.The text was updated successfully, but these errors were encountered: