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

Returns CancelResponse::REJECT while goal handle failed to transit to CANCELING state #1641

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion rclcpp_action/include/rclcpp_action/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,11 @@ class Server : public ServerBase, public std::enable_shared_from_this<Server<Act
if (goal_handle) {
resp = handle_cancel_(goal_handle);
if (CancelResponse::ACCEPT == resp) {
goal_handle->_cancel_goal();
try {
goal_handle->_cancel_goal();
} catch (const rclcpp::exceptions::RCLError & ex) {
KavenYau marked this conversation as resolved.
Show resolved Hide resolved
return CancelResponse::REJECT;
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
return resp;
Expand Down
11 changes: 5 additions & 6 deletions rclcpp_action/test/test_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1234,14 +1234,10 @@ class TestDeadlockServer : public TestServer
this->TryLockFor(lock, std::chrono::milliseconds(1000));
return rclcpp_action::GoalResponse::ACCEPT_AND_EXECUTE;
},
[this](std::shared_ptr<GoalHandle> handle) {
[this](std::shared_ptr<GoalHandle>) {
// instead of making a deadlock, check if it can acquire the lock in a second
std::unique_lock<std::recursive_timed_mutex> lock(server_mutex_, std::defer_lock);
this->TryLockFor(lock, std::chrono::milliseconds(1000));
// TODO(KavenYau): this check may become obsolete with https://github.com/ros2/rclcpp/issues/1599
if (!handle->is_active()) {
return rclcpp_action::CancelResponse::REJECT;
}
return rclcpp_action::CancelResponse::ACCEPT;
},
[this](std::shared_ptr<GoalHandle> handle) {
Expand Down Expand Up @@ -1316,6 +1312,9 @@ TEST_F(TestDeadlockServer, deadlock_while_succeed_and_canceled)
send_goal_request(node_, uuid1_);
std::thread t(&TestDeadlockServer::GoalSucceeded, this);
rclcpp::sleep_for(std::chrono::milliseconds(50));
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
send_cancel_request(node_, uuid1_);
auto response_ptr = send_cancel_request(node_, uuid1_);

// current goal handle is not cancelable, so it returns ERROR_REJECTED
EXPECT_EQ(CancelResponse::ERROR_REJECTED, response_ptr->return_code);
t.join();
}