ros2
runtime_error
ai_generated
true
运行时错误:无法取消正在取消中的目标
RuntimeError: Cannot cancel goal that is already being cancelled
ID: ros2/nav2-cancel-goal-multiple-times
85%修复率
85%置信度
1证据数
2024-02-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| ros2-humble | active | — | — | — |
| ros2-iron | active | — | — | — |
| ros2-rolling | active | — | — | — |
根因分析
Nav2动作服务器不支持对同一目标并发取消请求;多次调用取消会触发动作服务器内部状态机的竞态条件。
English
Nav2 action server does not support concurrent cancel requests on the same goal; calling cancel multiple times triggers a race condition in the action server's internal state machine.
官方文档
https://docs.nav2.org/behavior_trees/overview.html解决方案
-
在取消前检查目标是否处于终端状态:if (goal_handle->get_status() == action_msgs::msg::GoalStatus::STATUS_ACCEPTED || goal_handle->get_status() == action_msgs::msg::GoalStatus::STATUS_EXECUTING) { goal_handle->cancel(); } -
使用互斥锁序列化取消调用:std::lock_guard<std::mutex> lock(cancel_mutex_); if (!cancel_in_progress_) { cancel_in_progress_ = true; goal_handle->cancel(); cancel_in_progress_ = false; }
无效尝试
常见但无效的做法:
-
70% 失败
Race still occurs if two cancel calls happen within the sleep window; not a deterministic fix.
-
60% 失败
Error is suppressed but the action server state may remain inconsistent, leading to future crashes.