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

Aperta
#2,534 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
cpp
Ambito
api

Direzione di ricerca

Inizia confrontando rclcpp::Client::async_send_request e spin_until_future_complete con l’esempio funzionante di promise/callback e l’implementazione di rclcpp::SyncParametersClient. L’issue collega anche l’implementazione di ros2cli call.py per il confronto. Il lavoro sarà considerato completato quando sarà stato identificato il motivo per cui il percorso diretto con future causa un segmentation fault e saranno state documentate indicazioni generali sull’uso di async_send_request.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

more-information-needed

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?
Lingua principale
C++
Stelle
829
Fork
587
Merge medio
4g 6h
PR unite (30g)
30

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ros2/rclcpp

Tutte le issue di ros2/rclcpp

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.