ros2
runtime_error
ai_generated
true
rclcpp: 检测到死锁:回调在同一个互斥回调组中等待另一个回调
rclcpp: Deadlock detected: callback waiting for another callback in same MutuallyExclusiveCallbackGroup
ID: ros2/rclcpp-dual-mode-callback-group-deadlock
85%修复率
90%置信度
1证据数
2024-01-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| ROS2 Humble (rclcpp 16.0.0) | active | — | — | — |
| ROS2 Iron (rclcpp 17.0.0) | active | — | — | — |
| ROS2 Rolling (rclcpp 18.0.0) | active | — | — | — |
根因分析
互斥回调组中的某个回调阻塞在需要同一组中另一个回调的服务或动作调用上,导致死锁,因为该组一次只允许一个回调执行。
English
A callback in a MutuallyExclusiveCallbackGroup is blocking on a service or action call that requires another callback in the same group, causing a deadlock because the group only allows one callback at a time.
官方文档
https://docs.ros2.org/latest/api/rclcpp/classrclcpp_1_1CallbackGroup.html解决方案
-
将阻塞的服务调用移动到单独的回调组(例如ReentrantCallbackGroup),使其不会阻塞原始组:auto callback_group = this->create_callback_group(rclcpp::CallbackGroupType::Reentrant);
-
使用异步服务客户端以避免完全阻塞回调:auto future = client->async_send_request(request);
无效尝试
常见但无效的做法:
-
Increase the callback group's thread count or use a ReentrantCallbackGroup
60% 失败
Reentrant allows concurrent execution but does not solve the logical dependency; the service call still blocks.
-
Add a sleep or yield in the callback
95% 失败
Sleeping does not release the callback group lock; the deadlock persists.