Skip to content

Commit

Permalink
update RCL_RET_TIMEOUT error handling with action service response. (#…
Browse files Browse the repository at this point in the history
…1258)

* update RCL_RET_TIMEOUT error handling with action service response.

Signed-off-by: Tomoya Fujita <[email protected]>

* address review comment.

Signed-off-by: Tomoya Fujita <[email protected]>

---------

Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya authored Mar 27, 2024
1 parent a3ecd7e commit 2ec6797
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion rclpy/rclpy/action/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,12 @@ async def _execute_cancel_request(self, request_header_and_message):
# Remove from response
cancel_response.goals_canceling.remove(goal_info)

self._handle.send_cancel_response(request_header, cancel_response)
try:
# If the client goes away anytime before this, sending the goal response may fail.
# Catch the exception here and go on so we don't crash.
self._handle.send_cancel_response(request_header, cancel_response)
except RCLError:
self._logger.warn('Failed to send cancel response (the client may have gone away)')

async def _execute_get_result_request(self, request_header_and_message):
request_header, result_request = request_header_and_message
Expand Down
10 changes: 9 additions & 1 deletion rclpy/src/rclpy/action_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,15 @@ ActionServer::take_result_request(py::object pymsg_type)
rcl_ret_t ret = rcl_action_send_ ## Type ## _response( \
rcl_action_server_.get(), header, ros_response.get()); \
if (RCL_RET_OK != ret) { \
throw rclpy::RCLError("Failed to send " #Type " response"); \
if (RCL_RET_TIMEOUT == ret) { \
int stack_level = 1; \
PyErr_WarnFormat( \
PyExc_RuntimeWarning, stack_level, "failed to send response (timeout): %s", \
rcl_get_error_string().str); \
rcl_reset_error(); \
} else { \
throw rclpy::RCLError("Failed to send " #Type " response"); \
} \
}

void
Expand Down

0 comments on commit 2ec6797

Please sign in to comment.