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

Program exits with code -11 when using async_send_request to set parameters in ROS 2 C++ client #2534

Open
huweiATgithub opened this issue May 20, 2024 · 1 comment
Labels
more-information-needed Further information is required

Comments

@huweiATgithub
Copy link

Bug report

Required Info:

  • Operating System:
    • Ubuntu 22.04
  • Installation type:
    • binary (apt)
  • Version or commit hash:
    • humble
  • DDS implementation:
    • default
  • Client library (if applicable):
    • rclcpp

Steps to reproduce issue

I am encountering a segmentation fault (exit code -11) when using the async_send_request method to set parameters in a ROS 2 C++ client. Below is the relevant code snippet:

const auto set_parameters_req = std::make_shared<rcl_interfaces::srv::SetParameters::Request>();
auto set_parameters_resp = set_parameters_client_->async_send_request(set_parameters_req);
EXPECT_EQ(rclcpp::FutureReturnCode::SUCCESS, rclcpp::spin_until_future_complete(node_, set_parameters_resp));

Actual behavior

When executing the above code, the program exits with code -11 at the spin_until_future_complete call.

Additional information

The direct use of ros2 service call from the command line works correctly, and its implementation in Python at ros2cli GitHub resembles the C++ code I am using.

An alternative approach, using a promise and callback with async_send_request, does work as shown below. This approach is inspired by the implementation in rclcpp::SyncParametersClient:

auto promise_result = std::make_shared<std::promise<std::vector<rcl_interfaces::msg::SetParametersResult>>>();
set_parameters_client_->async_send_request(
  set_parameters_req,
  [promise_result, future_result](rclcpp::Client<rcl_interfaces::srv::SetParameters>::SharedFuture cb_f) {
    promise_result->set_value(cb_f.get()->results);
  }
);
rclcpp::spin_until_future_complete(test_node_, future_result);

Questions:

  • Why does the first approach result in a segmentation fault while the second approach and the Python version work correctly?
  • Are there any general rules or guidelines for using async_send_request in ROS 2 C++ clients to avoid such issues?
@fujitatomoya
Copy link
Collaborator

@huweiATgithub

i know the there are many test cases something like this,

auto result = client->async_send_request(request);
ASSERT_EQ(
rclcpp::spin_until_future_complete(node_, result),
rclcpp::FutureReturnCode::SUCCESS);

and all tests do pass.

can you share more details like stack trace information, reproducible colcon package?

@fujitatomoya fujitatomoya added the more-information-needed Further information is required label May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more-information-needed Further information is required
Projects
None yet
Development

No branches or pull requests

2 participants