Skip to content

Thread safe node.destroy_* - #319

Merged
sloretz merged 16 commits into
masterfrom
sloretz/thread_safe_destroy
May 1, 2019
Merged

sloretz merged 16 commits into
masterfrom
sloretz/thread_safe_destroy

Conversation

@sloretz

@sloretz sloretz commented Apr 24, 2019 •

Copy link
Copy Markdown
Contributor

Follow up to #318 and #330. This PR applies the changes done to Subscription to the rest of the entities on the node so they can all be destroyed safely.

  • destroy_publisher
  • destroy_client
  • destroy_service
  • destroy_timer
    • Clock used by timer safely destroyed
  • destroy_guard_condition

Not done in this PR. These might require a change to the waitable API.

  • action server
  • action client

@sloretz sloretz added the in progress Actively being worked on (Kanban column) label Apr 24, 2019
@sloretz sloretz self-assigned this Apr 24, 2019
@sloretz
sloretz force-pushed the sloretz/thread_safe_destroy branch from 7ba0972 to 0e8cda0 Compare April 25, 2019 22:17
@sloretz

sloretz commented Apr 25, 2019

Copy link
Copy Markdown
Contributor Author

I think I have to include destroy_node in this PR. This approach can change the order that entities get shut down.

# In another thread an executor is spinning
# srv destruction delayed because executor is waiting on service
node.destroy_service(srv)

# node is destroyed instantly; service still not destroyed because it's being used by executor
node.destroy_node()

# When executor shuts down the service is no longer being used, so it's destroyed
# since the node was destroyed first the service will segfault in rmw_fastrtps
executor.shutdown()

I'm thinking of chaining handles so that node.destroy_node() destroy's all node entities before allowing itself to be destroyed.

sloretz added 12 commits April 30, 2019 13:26
Publisher now uses Handle
pub.publisher_handle -> pub.handle
Added test for publisher destruction
Added rclpy_publisher_t to replace rcl_publisher_t

Signed-off-by: Shane Loretz<[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
Client now uses Handle
Client.client_handle and client_pointer replaced by client.handle
rclpy_destroy_entity no longer destroy's clients
Added test for client destruction
Client capsule uses rclpy_client_t instead of rcl_client_t

Signed-off-by: Shane Loretz <[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
@sloretz
sloretz force-pushed the sloretz/thread_safe_destroy branch from 052b0ed to e4ca965 Compare April 30, 2019 20:26
Comment thread rclpy/rclpy/executors.py
self._guard_condition = gc
self._guard_condition_handle = gc_handle
self._guard = GuardCondition(
callback=None, callback_group=None, context=self._context)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reusing GuardCondition to reuse executor code that uses guard_condition.handle

@sloretz sloretz added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Apr 30, 2019
@sloretz

sloretz commented Apr 30, 2019

Copy link
Copy Markdown
Contributor Author

Ready for review.

CI (testing rclpy)

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

@clalancette clalancette left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Partial review with some feedback on parts I know :). Will do some additional review after.

Comment thread rclpy/src/rclpy/_rclpy.c Resolved
Comment thread rclpy/src/rclpy/_rclpy.c Resolved

@clalancette clalancette left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All right, a few more review comments, mostly phrased as questions as I'm still getting a handle on how this works (pun intended).

Comment thread rclpy/rclpy/node.py Resolved
Comment thread rclpy/rclpy/node.py Outdated
return True
if publisher in self.publishers:
self.publishers.remove(publisher)
publisher.destroy()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For all of these destroy calls, do we need to check for the InvalidHandle exception? Is that a case that can happen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is. Maybe this should catch it and return False?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, that seems reasonable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

destroy_<entity>() catch InvalidHandle and return False in e630404

Comment thread rclpy/rclpy/executors.py Resolved
Comment thread rclpy/rclpy/executors.py Resolved

@clalancette clalancette left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The code looks good to me now, so I'll approve.

My only remaining question is whether we should open an issue for reducing the complexity here by introducing rmw_shutdown_but_not_fini for a future enhancement. Thoughts on that?

@sloretz

sloretz commented May 1, 2019

Copy link
Copy Markdown
Contributor Author

CI (testing rclpy)

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

@sloretz

sloretz commented May 1, 2019

Copy link
Copy Markdown
Contributor Author

My only remaining question is whether we should open an issue for reducing the complexity here by introducing rmw_shutdown_but_not_fini for a future enhancement. Thoughts on that?

I've gone back and forth between writing the issue on rmw vs making it a higher level feature of rcl. I opened ros2/rcl#429, but the solution seems a lot more complicated than I first thought. I put it in the backlog since it feels like it needs more thought.

@sloretz
sloretz merged commit d672075 into master May 1, 2019
@delete-merged-branch
delete-merged-branch Bot deleted the sloretz/thread_safe_destroy branch May 1, 2019 17:56
@sloretz sloretz removed the in review Waiting for review (Kanban column) label May 1, 2019
ryantqiu pushed a commit to snorkel-marlin-repos/ros2_rclpy_pr_319_7df4231b-f934-4cf6-a39d-fd3e0d569768 that referenced this pull request Oct 1, 2025
Original PR #319 by sloretz
Original: ros2/rclpy#319
ryantqiu added a commit to snorkel-marlin-repos/ros2_rclpy_pr_319_7df4231b-f934-4cf6-a39d-fd3e0d569768 that referenced this pull request Oct 1, 2025
Merged from original PR #319
Original: ros2/rclpy#319
ryantqiu pushed a commit to snorkel-marlin-repos/ros2_rclpy_pr_319_d3a46b59-16d6-4960-91e0-24b9ae7c5cb7 that referenced this pull request Oct 2, 2025
Original PR #319 by sloretz
Original: ros2/rclpy#319
ryantqiu added a commit to snorkel-marlin-repos/ros2_rclpy_pr_319_d3a46b59-16d6-4960-91e0-24b9ae7c5cb7 that referenced this pull request Oct 2, 2025
Merged from original PR #319
Original: ros2/rclpy#319
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