Skip to content

Make rmw_send_response take a const response - #437

Merged
ahcorde merged 1 commit into
ros2:rollingfrom
nobleo:fix/const-rmw-send-response
Nov 24, 2026
Merged

ahcorde merged 1 commit into
ros2:rollingfrom
nobleo:fix/const-rmw-send-response

Conversation

@Rayman

@Rayman Rayman commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

In ros2/examples#478 I've noticed that rclcpp send_reponse takes a mutable reference to the response. I think this a bug in the API as you only need a constant reference to serialize a message. The documentation for rmw verifies that:

Access to the given ROS service response is read-only but it is not synchronized.

* - Access to the given ROS service response is read-only but it is not synchronized.

This bug affects multiple layers, so I'm starting the discussion here if my assumptions are correct. Can we change the message to a const reference?

If we want this, this change must be accompanied by changes in the following packages:

  • rmw_implementation
  • rmw_fastrtps
  • rcl
  • rclcpp
  • Other rmw implementations (Cyclone DDS, Connext, Zenoh, ...)

The alternative to this is to do a const_cast in rclcpp.

Fixes # (issue)

Is this user-facing behavior change?

Did you use Generative AI?

GitHub Copilot with sonnet 5.5

Additional Information

In ros2/examples#478 I've noticed that
rclcpp send_reponse takes a mutable reference to the response. I think
this a bug in the API as you only need a constant reference to serialize
a message. The documentation for rmw verifies that:

  Access to the given ROS service response is read-only but it is not synchronized.
  https://github.com/ros2/rmw/blob/0932be49fb6b3c9a8f3de82cf894bb628d7af59c/rmw/include/rmw/rmw.h#L2403

This bug affects multiple layers, so I'm starting the discussion here if
my assumptions are correct. Can we change the message to a const
reference?

If we want this, this change must be accompanied by changes in the
following packages:
- rmw_implementation
- rmw_fastrtps
  rmw_fastrtps_cpp
- rcl
- rclcpp
- Other rmw implementations (Cyclone DDS, Connext, Zenoh, ...) need the
  same signature change.

The alternative to this is to do a const_cast in rclcpp.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Ramon Wijnands <[email protected]>
@mjcarroll

Copy link
Copy Markdown
Member

Yeah, I think this is the right move, and you have already identified the packages that would need to be updated (as well as any other rmw implementation).

@fujitatomoya

Copy link
Copy Markdown
Collaborator

@skyegalaxy @Rayman i created the corresponding PRs above to go with this PR, all of them are quick patches, can you review and approve?

@ahcorde

ahcorde commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Pulls: ros2/rmw_implementation#313, ros2/rmw_fastrtps#968, ros2/rmw_cyclonedds#640, ros2/rmw_connextdds#267, ros2/rclcpp#3400, ros2/rcl#1358, #437, ros2/rmw_zenoh#1100
Gist: https://gist.githubusercontent.com/ahcorde/eb382351f014edb273df7abce4f1b23e/raw/3db110452676e687dcc483a63a997ac8864ae6f9/ros2.repos
BUILD args: --packages-above-and-dependencies rmw_zenoh_cpp rmw rcl rclcpp rmw_connextdds rmw_cyclonedds_cpp rmw_fastrtps_cpp rmw_implementation
TEST args: --packages-above rmw_zenoh_cpp rmw rcl rclcpp rmw_connextdds rmw_cyclonedds_cpp rmw_fastrtps_cpp rmw_implementation
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/21041

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@Rayman

Rayman commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

I had all the diffs the same as you, except the rcl package: ros2/rcl#1358

@kscottz

kscottz commented Nov 12, 2026

Copy link
Copy Markdown

Ready to merge?

@ahcorde

ahcorde commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Pulls: ros2/rmw_implementation#313, ros2/rmw_fastrtps#968, ros2/rmw_cyclonedds#640, ros2/rmw_connextdds#267, ros2/rclcpp#3400, ros2/rcl#1358, #437, ros2/rmw_zenoh#1100
Gist: https://gist.githubusercontent.com/ahcorde/ccc7052c5e2d6d7aad22271db71c5427/raw/3db110452676e687dcc483a63a997ac8864ae6f9/ros2.repos
BUILD args: --packages-above-and-dependencies rmw_zenoh_cpp rmw rcl rclcpp rmw_connextdds rmw_cyclonedds_cpp rmw_fastrtps_cpp rmw_implementation
TEST args: --packages-above rmw_zenoh_cpp rmw rcl rclcpp rmw_connextdds rmw_cyclonedds_cpp rmw_fastrtps_cpp rmw_implementation
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/21243

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

ahcorde pushed a commit to ros2/rmw_implementation that referenced this pull request Nov 24, 2026
Update the rmw_send_response forwarding signature to const void * ros_response.

Companion change for ros2/rmw#437, which makes rmw_send_response take a const void * ros_response. A response only needs to be read to be serialized and sent, so the pointer should be const, consistent with rmw_send_request.

Signed-off-by: Tomoya Fujita <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
ahcorde pushed a commit to ros2/rmw_fastrtps that referenced this pull request Nov 24, 2026
Update rmw_send_response and the shared __rmw_send_response helper to take const void * ros_response. The response is already passed to the DataWriter through a const_cast, so no behavior changes.

Companion change for ros2/rmw#437, which makes rmw_send_response take a const void * ros_response. A response only needs to be read to be serialized and sent, so the pointer should be const, consistent with rmw_send_request.

Signed-off-by: Tomoya Fujita <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
ahcorde pushed a commit to ros2/rmw_cyclonedds that referenced this pull request Nov 24, 2026
Update rmw_send_response to take const void * ros_response. The internal rmw_send_response_request helper already took a const pointer, so no behavior changes.

Companion change for ros2/rmw#437, which makes rmw_send_response take a const void * ros_response. A response only needs to be read to be serialized and sent, so the pointer should be const, consistent with rmw_send_request.

Signed-off-by: Tomoya Fujita <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
ahcorde pushed a commit to ros2/rmw_connextdds that referenced this pull request Nov 24, 2026
Update rmw_send_response (Connext Pro and Micro entry points) and rmw_api_connextdds_send_response to take const void * ros_response. RMW_Connext_Service::send_response already took a const pointer, so no behavior changes. Both the rmw_connextdds and rmw_connextdds_common copies of the sources are updated.

Companion change for ros2/rmw#437, which makes rmw_send_response take a const void * ros_response. A response only needs to be read to be serialized and sent, so the pointer should be const, consistent with rmw_send_request.

Signed-off-by: Tomoya Fujita <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
ahcorde pushed a commit to ros2/rclcpp that referenced this pull request Nov 24, 2026
Service<ServiceT>::send_response now takes const ServiceT::Response &, and GenericService::send_response takes const SharedResponse &. The response is only forwarded to rcl_send_response, which now takes a const pointer. Existing callers passing non-const responses continue to compile.

Companion change for ros2/rmw#437, which makes rmw_send_response take a const void * ros_response. A response only needs to be read to be serialized and sent, so the pointer should be const, consistent with rmw_send_request.

Signed-off-by: Tomoya Fujita <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
ahcorde pushed a commit to ros2/rcl that referenced this pull request Nov 24, 2026
Update rcl_send_response and the rcl_action_send_{goal,result,cancel}_response functions to take const void * for the response. The response is only read and forwarded to rmw_send_response, and the documentation already states that it is left unmodified. This is also consistent with rcl_send_request and the rcl_action_send_*_request functions, which already take const void *.

Companion change for ros2/rmw#437, which makes rmw_send_response take a const void * ros_response. A response only needs to be read to be serialized and sent, so the pointer should be const, consistent with rmw_send_request.

Signed-off-by: Tomoya Fujita <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
@ahcorde
ahcorde merged commit 3bb9e87 into ros2:rolling Nov 24, 2026
3 checks passed
ahcorde pushed a commit to ros2/rmw_zenoh that referenced this pull request Nov 24, 2026
Update rmw_send_response and ServiceData::send_response to take const void * ros_response. The type support serialization functions already take a const pointer, so no behavior changes.

Companion change for ros2/rmw#437, which makes rmw_send_response take a const void * ros_response. A response only needs to be read to be serialized and sent, so the pointer should be const, consistent with rmw_send_request.

Signed-off-by: Tomoya Fujita <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
benaliabderrahmane added a commit to benaliabderrahmane/rmw_unix_socket_cpp that referenced this pull request Nov 30, 2026
…w 7.11.4) (#104)

ros2/rmw#437, released in rmw 7.11.4 on Rolling, changed the response
parameter of rmw_send_response from `void *` to `const void *`. Our
definition sits in an extern "C" block, so the old signature is now a
"conflicting declaration of C function" and the Rolling build farm job
(Rbin_unv8_uRv8 rmw_unix_socket_cpp #2) fails.

Gate the parameter on rmw_VERSION >= 7.11.4. jazzy (7.3.4) and lyrical
(7.10.3) keep `void *`; the body already passes the pointer to
shm_serialize_prepare_send, which takes `const void *`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants