Repository navigation
Make destroy_node thread safe - #330
Merged
Merged
Conversation
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]>
Contributor
Author
|
CI (testing all packages above rclpy)
|
6 tasks done
Signed-off-by: Shane Loretz <[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
Contributor
Author
Signed-off-by: Shane Loretz <[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
sloretz
commented
Apr 30, 2019
| # Assume lock is held | ||
| assert not self.__lock.acquire(blocking=False) | ||
| # Assume capsule has not been destroyed | ||
| assert self.__valid |
Contributor
Author
There was a problem hiding this comment.
Destruction can be delayed waiting for dependents. Previously self.__valid = False meant the capsule itself has been destroyed. Now setting it to false means destroy() was called and __use_count hit zero. The purpose is to prevent new users of this handle while waiting for dependent handles to be destroyed.
Contributor
Author
dirk-thomas
approved these changes
Apr 30, 2019
dirk-thomas
left a comment
Member
There was a problem hiding this comment.
LGTM (after convincing myself I understood how the call hierarchy happens)
Signed-off-by: Shane Loretz <[email protected]>
Contributor
Author
|
CI (testing rclpy with 8c95ea6) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Blocks #319
I was going to make this part of #319, but I think it would be easier to review separately. This makes
Node.handleuse theHandleclass from #308. It also addshandle.requires(another_handle)to make surehandleis destroyed beforeanother_handle.Problem this solves
#308 makes
destroy_subscriptionthread safe by delaying destruction if the handle is currently being used. This makes it possible for a subscription to be destroyed after the node; which crashes when doing the same strategy with services using fast-rtps. See #319 (comment) for a better explanation.Breaking changes
node.destroy_node()either returnedTrueor raised an exception. I removed the return value since it was only everTrue.node.handlewas set toNoneafter the node was destroyed. Now it raisesInvalidHandlewhen someone tries to use it after it is destroyed.node.handlewas a pycapsule and could be used directly. Now one must use:How handle.requires() works
Subscriptions must be destroyed before the node that created them, so
When
node.handle.destroy()is called the subscription handle is destroyed first. Once the node handle is no longer being used it will mark itself invalid so no one else can use it. Then the node handle tells the subscription handle to destroy itself. Once the subscription handle is no longer in use it will delete itself, and then tell the node it can destroy itself.If the user does not call
destroy()on either handle, the subscription handle holds a reference to the node handle so the subscription handle will be garbage collected first. The node handle only holds a weak reference to the subscription handle.Next steps
After incorporating feedback, assuming this approach is OK I would like to merge this PR. Then I'll rebase #319 to make all the other entities require the
nodeso everything can be destroyed safely.