{
  "id": "ros2/nav2-cancel-goal-multiple-times",
  "signature": "RuntimeError: Cannot cancel goal that is already being cancelled",
  "signature_zh": "运行时错误：无法取消正在取消中的目标",
  "regex": "RuntimeError: Cannot cancel goal that is already being cancelled",
  "domain": "ros2",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "Nav2动作服务器不支持对同一目标并发取消请求；多次调用取消会触发动作服务器内部状态机的竞态条件。",
  "versions": [
    {
      "version": "ros2-humble",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "ros2-iron",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "ros2-rolling",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Race still occurs if two cancel calls happen within the sleep window; not a deterministic fix.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Error is suppressed but the action server state may remain inconsistent, leading to future crashes.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check if the goal is already in a terminal state before calling cancel: if (goal_handle->get_status() == action_msgs::msg::GoalStatus::STATUS_ACCEPTED || goal_handle->get_status() == action_msgs::msg::GoalStatus::STATUS_EXECUTING) { goal_handle->cancel(); }",
      "success_rate": 0.9,
      "how": "Check if the goal is already in a terminal state before calling cancel: if (goal_handle->get_status() == action_msgs::msg::GoalStatus::STATUS_ACCEPTED || goal_handle->get_status() == action_msgs::msg::GoalStatus::STATUS_EXECUTING) { goal_handle->cancel(); }",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a mutex to serialize cancel calls: std::lock_guard<std::mutex> lock(cancel_mutex_); if (!cancel_in_progress_) { cancel_in_progress_ = true; goal_handle->cancel(); cancel_in_progress_ = false; }",
      "success_rate": 0.85,
      "how": "Use a mutex to serialize cancel calls: std::lock_guard<std::mutex> lock(cancel_mutex_); if (!cancel_in_progress_) { cancel_in_progress_ = true; goal_handle->cancel(); cancel_in_progress_ = false; }",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在取消前检查目标是否处于终端状态：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; }"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.nav2.org/behavior_trees/overview.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-02-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}