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

Guard against TOCTTOU with rclcpp::ok and rclcpp:spin_some #459

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions test_rclcpp/test/test_client_scope_consistency_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ int main(int argc, char ** argv)
"client_scope", handle_add_two_ints, rmw_qos_profile);

rclcpp::WallRate loop_rate(30);
while (rclcpp::ok()) {
rclcpp::spin_some(node);
loop_rate.sleep();
try {
while (rclcpp::ok()) {
rclcpp::spin_some(node);
loop_rate.sleep();
}
} catch (const rclcpp::exceptions::RCLError & ex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in other places, we should really fix this issue so this "catch all rcl errors" thing isn't needed (this mechanism can be masking actual errors).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I think this is the most relevant open issue at the moment: ros2/rclcpp#1139

RCLCPP_ERROR(node->get_logger(), "failed with %s", ex.what());
}
rclcpp::shutdown();
return 0;
Expand Down
10 changes: 7 additions & 3 deletions test_rclcpp/test/test_client_scope_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ int main(int argc, char ** argv)
"client_scope", handle_add_two_ints);

rclcpp::WallRate loop_rate(30);
while (rclcpp::ok()) {
rclcpp::spin_some(node);
loop_rate.sleep();
try {
while (rclcpp::ok()) {
rclcpp::spin_some(node);
loop_rate.sleep();
}
} catch (const rclcpp::exceptions::RCLError & ex) {
RCLCPP_ERROR(node->get_logger(), "failed with %s", ex.what());
}
rclcpp::shutdown();
return 0;
Expand Down