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

Return service from node_type_description_service_init #1112

Merged
merged 5 commits into from Oct 30, 2023

Conversation

mjcarroll
Copy link
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>
rcl/src/rcl/node.c Outdated Show resolved Hide resolved
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>
rcl/include/rcl/node.h Show resolved Hide resolved
rcl/include/rcl/node.h Show resolved Hide resolved
Signed-off-by: Michael Carroll <mjcarroll@intrinsic.ai>
Signed-off-by: Michael Carroll <mjcarroll@intrinsic.ai>
@mjcarroll
Copy link
Member Author

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

Copy link
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
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
3 checks passed
@delete-merged-branch delete-merged-branch bot deleted the mjcarroll/fini_service branch October 30, 2023 19:24
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.

None yet

2 participants