ros2 runtime_error ai_generated true

rclcpp::exceptions::RCLError:发布参数事件失败:无法在回调组中调用发布

rclcpp::exceptions::RCLError: failed to publish parameter event: cannot call publish while in a callback group

ID: ros2/rclcpp-parameter-event-callback-deadlock

其他格式: JSON · Markdown 中文 · English
85%修复率
84%置信度
1证据数
2024-04-12首次发现

版本兼容性

版本状态引入弃用备注
ros2-humble active
ros2-iron active
ros2-rolling active

根因分析

参数事件回调尝试在触发回调的同一主题上发布消息,导致回调组执行器死锁。

English

A parameter event callback tries to publish a message on the same topic that triggered the callback, causing a deadlock in the callback group's executor.

generic

官方文档

https://docs.ros2.org/latest/api/rclcpp/classrclcpp_1_1ParameterEventHandler.html

解决方案

  1. 为参数事件订阅者使用单独的回调组:auto param_event_group = create_callback_group(rclcpp::CallbackGroupType::Reentrant); auto sub = create_subscription<rcl_interfaces::msg::ParameterEvent>('/parameter_events', 10, callback, param_event_group);
  2. 使用定时器异步发布参数事件:在回调中,安排一个定时器在回调返回后发布消息。

无效尝试

常见但无效的做法:

  1. 90% 失败

    MutuallyExclusive groups still deadlock if the same callback tries to publish to the triggering topic.

  2. 70% 失败

    The event callback is still in the same callback group; publishing from another node doesn't resolve the deadlock.