Skip to content

Return service from node_type_description_service_init#1112

Merged
mjcarroll merged 5 commits intorollingfrom
mjcarroll/fini_service
Oct 30, 2023
Merged

Return service from node_type_description_service_init#1112
mjcarroll merged 5 commits intorollingfrom
mjcarroll/fini_service

Conversation

@mjcarroll
Copy link
Copy Markdown
Member

@mjcarroll mjcarroll commented Oct 26, 2023

This changes the mechanism of rcl_node_type_description_service_init to populate a user-provided service.

This makes it the calling user's responsibility to call rcl_service_fini on the returned service, making it more in line with the rest of the rcl API.

This was discovered when working with the new rclcpp::WaitSet implementation.

The main issue is that the executor needs to share ownership with objects that it is wait-ing on for the entire duration of the wait, even if a node is removed from the executor at that time. That is, the executor doesn't have knowledge of the nodes so much as the waitable objects in the collection.

In this current implementation, the type_description was being fini-ed during the NodeTypeDescriptions destructor here: https://github.com/ros2/rclcpp/blob/fcbe64cff4bea3109531254ceb2955dc4b1bb320/rclcpp/src/rclcpp/node_interfaces/node_type_descriptions.cpp#L128-L139. This could cause a situation where a service is cleaned up while we are still waiting on it, and yields a segfault afterwards.

After discussion with @clalancette, it seems the better approach is to have the user init the service and then be responsible for managing the lifetime of that service through their client library (eg rclcpp::Service)

This makes the caller responsible for cleaning up the service.

Signed-off-by: Michael Carroll <mjcarroll@intrinsic.ai>
@mjcarroll mjcarroll force-pushed the mjcarroll/fini_service branch from 54a4d99 to 43dfecc Compare October 26, 2023 21:13
Signed-off-by: Michael Carroll <mjcarroll@intrinsic.ai>
@mjcarroll mjcarroll changed the title Make the fini of the type description service explicit Return service from node_type_description_service_init Oct 27, 2023
Signed-off-by: Michael Carroll <mjcarroll@intrinsic.ai>
Michael Carroll added 2 commits October 28, 2023 02:33
Signed-off-by: Michael Carroll <mjcarroll@intrinsic.ai>
Signed-off-by: Michael Carroll <mjcarroll@intrinsic.ai>
@mjcarroll
Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

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

lgtm

@mjcarroll mjcarroll self-assigned this Oct 30, 2023
@mjcarroll
Copy link
Copy Markdown
Member Author

One more run after some rebase/force-push:

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

@mjcarroll mjcarroll merged commit 1b79535 into rolling Oct 30, 2023
@delete-merged-branch delete-merged-branch bot deleted the mjcarroll/fini_service branch October 30, 2023 19:24
clalancette added a commit that referenced this pull request Jun 25, 2024
In particular, make sure to match all service_description_init
with the appropriate finis.  While we are in here, also add in
a "service_not_exists" function that will quit much earlier,
speeding up the test.

This is essentially a backport of #1107
and parts of #1112, but adapted
for Iron.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
clalancette added a commit that referenced this pull request Jun 25, 2024
In particular, make sure to match all service_description_init
with the appropriate finis.  While we are in here, also add in
a "service_not_exists" function that will quit much earlier,
speeding up the test.

This is essentially a backport of #1107
and parts of #1112, but adapted
for Iron.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
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.

2 participants