ros2 / ros2/rclcpp

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

Open
#2,534 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

more-information-needed
Dominant language
C++
Stars
805
Forks
564
Avg merge
1d 17h
Merged PRs (30d)
27

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing rclcpp::Client::async_send_request and spin_until_future_complete with the working promise/callback example and rclcpp::SyncParametersClient implementation. The issue also links the ros2cli call.py implementation for comparison. Done means identifying why the direct future path segfaults and documenting general async_send_request usage guidance.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.