Skip to content

Commit 2ec6797

Browse files
authored
update RCL_RET_TIMEOUT error handling with action service response. (#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]>
1 parent a3ecd7e commit 2ec6797

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

rclpy/rclpy/action/server.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,12 @@ async def _execute_cancel_request(self, request_header_and_message):
387387
# Remove from response
388388
cancel_response.goals_canceling.remove(goal_info)
389389

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

392397
async def _execute_get_result_request(self, request_header_and_message):
393398
request_header, result_request = request_header_and_message

rclpy/src/rclpy/action_server.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,15 @@ ActionServer::take_result_request(py::object pymsg_type)
140140
rcl_ret_t ret = rcl_action_send_ ## Type ## _response( \
141141
rcl_action_server_.get(), header, ros_response.get()); \
142142
if (RCL_RET_OK != ret) { \
143-
throw rclpy::RCLError("Failed to send " #Type " response"); \
143+
if (RCL_RET_TIMEOUT == ret) { \
144+
int stack_level = 1; \
145+
PyErr_WarnFormat( \
146+
PyExc_RuntimeWarning, stack_level, "failed to send response (timeout): %s", \
147+
rcl_get_error_string().str); \
148+
rcl_reset_error(); \
149+
} else { \
150+
throw rclpy::RCLError("Failed to send " #Type " response"); \
151+
} \
144152
}
145153

146154
void

0 commit comments

Comments
 (0)