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

[rclcpp_action] Action client holds weak pointers to goal handles #1122

Merged
merged 5 commits into from
May 22, 2020

Conversation

jacobperron
Copy link
Member

@jacobperron jacobperron commented May 20, 2020

Fixes #861

It is against the design of ROS actions to rely on the status topic for the core implementation,
instead it should just be used for introspection.

Rather than relying on the status topic to remove references to goal handles, the action client
instead holds weak pointers to the goal handles. This way, as long as a user holds a reference to
the goal handle they can use it to interact with the action client.

Draft PR for now as I try to determine if this actually fixes the issue (hopefully with a reliable reproduction of the bug).

For a reproduction, see #861 (comment)

Fixes #861

It is against the design of ROS actions to rely on the status topic for the core implementation,
instead it should just be used for introspection.

Rather than relying on the status topic to remove references to goal handles, the action client
instead holds weak pointers to the goal handles. This way as long as a user holds a reference to
the goal handle they can use it to interact with the action client.

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
Signed-off-by: Jacob Perron <jacob@openrobotics.org>
@jacobperron jacobperron marked this pull request as ready for review May 21, 2020 01:44
@jacobperron
Copy link
Member Author

Testing packages above rclcpp_action:

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

@jacobperron
Copy link
Member Author

I'll still have to update the examples that aren't already maintaining a reference to the goal handle. Otherwise, I expect them to break as pointed out in #861 (comment).

Copy link
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

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

LGTM

@jacobperron
Copy link
Member Author

So, it turns out this change didn't break our examples, because of a subtle way the lifetime of the goal handle is extended. If the user registers a result callback when sending the goal, then the shared_ptr is kept alive by the action client by passing it to this lambda:

this->send_result_request(
std::static_pointer_cast<void>(goal_result_request),
[goal_handle, this](std::shared_ptr<void> response) mutable
{

I guess this is fine, though I think it's worth adding some documentation regarding the lifetime of the goal handle.

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
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

@jacobperron jacobperron merged commit c7b62bf into master May 22, 2020
@delete-merged-branch delete-merged-branch bot deleted the jacob/client_holds_weak_goal_handles branch May 22, 2020 18:41
DensoADAS pushed a commit to DensoADAS/rclcpp that referenced this pull request Jul 7, 2020
…s2#1122)

* [rclcpp_action] Action client holds weak pointers to goal handles

Fixes ros2#861

It is against the design of ROS actions to rely on the status topic for the core implementation,
instead it should just be used for introspection.

Rather than relying on the status topic to remove references to goal handles, the action client
instead holds weak pointers to the goal handles. This way as long as a user holds a reference to
the goal handle they can use it to interact with the action client.

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Move cleanup logic to the end of the function

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Add TODO

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Log debug messages when dropping a weak references to goal handles

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Improve documentation

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
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.

rclcpp_action: In certain circumstances, goal can be gone before client gets result
5 participants