Skip to content

Commit d051b8a

Browse files
authored
Returns CancelResponse::REJECT while goal handle failed to transit to CANCELING state (#1641)
Signed-off-by: Kaven Yau <[email protected]>
1 parent 6806cdf commit d051b8a

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

rclcpp_action/include/rclcpp_action/server.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,14 @@ class Server : public ServerBase, public std::enable_shared_from_this<Server<Act
369369
if (goal_handle) {
370370
resp = handle_cancel_(goal_handle);
371371
if (CancelResponse::ACCEPT == resp) {
372-
goal_handle->_cancel_goal();
372+
try {
373+
goal_handle->_cancel_goal();
374+
} catch (const rclcpp::exceptions::RCLError & ex) {
375+
RCLCPP_DEBUG(
376+
rclcpp::get_logger("rclcpp_action"),
377+
"Failed to cancel goal in call_handle_cancel_callback: %s", ex.what());
378+
return CancelResponse::REJECT;
379+
}
373380
}
374381
}
375382
return resp;

rclcpp_action/test/test_server.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,14 +1234,10 @@ class TestDeadlockServer : public TestServer
12341234
this->TryLockFor(lock, std::chrono::milliseconds(1000));
12351235
return rclcpp_action::GoalResponse::ACCEPT_AND_EXECUTE;
12361236
},
1237-
[this](std::shared_ptr<GoalHandle> handle) {
1237+
[this](std::shared_ptr<GoalHandle>) {
12381238
// instead of making a deadlock, check if it can acquire the lock in a second
12391239
std::unique_lock<std::recursive_timed_mutex> lock(server_mutex_, std::defer_lock);
12401240
this->TryLockFor(lock, std::chrono::milliseconds(1000));
1241-
// TODO(KavenYau): this check may become obsolete with https://github.com/ros2/rclcpp/issues/1599
1242-
if (!handle->is_active()) {
1243-
return rclcpp_action::CancelResponse::REJECT;
1244-
}
12451241
return rclcpp_action::CancelResponse::ACCEPT;
12461242
},
12471243
[this](std::shared_ptr<GoalHandle> handle) {
@@ -1316,6 +1312,9 @@ TEST_F(TestDeadlockServer, deadlock_while_succeed_and_canceled)
13161312
send_goal_request(node_, uuid1_);
13171313
std::thread t(&TestDeadlockServer::GoalSucceeded, this);
13181314
rclcpp::sleep_for(std::chrono::milliseconds(50));
1319-
send_cancel_request(node_, uuid1_);
1315+
auto response_ptr = send_cancel_request(node_, uuid1_);
1316+
1317+
// current goal handle is not cancelable, so it returns ERROR_REJECTED
1318+
EXPECT_EQ(CancelResponse::ERROR_REJECTED, response_ptr->return_code);
13201319
t.join();
13211320
}

0 commit comments

Comments
 (0)