Skip to content

Commit

Permalink
reject cancel request if failed to transit to CANCEL_GOAL state. (#791)…
Browse files Browse the repository at this point in the history
… (#795)

* reject cancel request if failed to transit to CANCEL_GOAL state.

Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>

* catch RCLError instead of Exception.

Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>

Co-authored-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
  • Loading branch information
jacobperron and fujitatomoya committed May 13, 2021
1 parent bfb7bc2 commit 10bae22
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion rclpy/rclpy/action/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
from rclpy.type_support import check_for_type_support
from rclpy.waitable import NumberOfEntities, Waitable

# Re-export exception defined in _rclpy C extension.
RCLError = _rclpy.RCLError


class GoalResponse(Enum):
"""Possible goal responses."""
Expand Down Expand Up @@ -375,7 +378,15 @@ async def _execute_cancel_request(self, request_header_and_message):

if CancelResponse.ACCEPT == response:
# Notify goal handle
goal_handle._update_state(GoalEvent.CANCEL_GOAL)
try:
# If the goal's just succeeded after user cancel callback
# that will generate an exception from invalid transition.
goal_handle._update_state(GoalEvent.CANCEL_GOAL)
except RCLError as ex:
self._node.get_logger().debug(
'Failed to cancel goal in cancel callback: {0}'.format(ex))
# Remove from response since goal has been succeeded
cancel_response.goals_canceling.remove(goal_info)
else:
# Remove from response
cancel_response.goals_canceling.remove(goal_info)
Expand Down

0 comments on commit 10bae22

Please sign in to comment.