-
Notifications
You must be signed in to change notification settings - Fork 425
Description
Context
While reviewing the controller_manager architecture, I noticed what appears to be a real-time safety concern. Verified on commit a03be840 of ros-controls/ros2_control:master.
Problem
In controller_manager.cpp:L3369, publish_activity() is called from within the RT update() loop during fallback controller activation. However, publish_activity() acquires a lock_guard on rt_controllers_wrapper_.controllers_lock_ at L4083.
Since ros2_control_node runs the update loop on a SCHED_FIFO thread (ros2_control_node.cpp:L107), this mutex acquisition in the critical path could lead to priority inversion or unexpected jitter.
Proposed Fix
I've drafted a potential fix locally following the AsyncFunctionHandler pattern already used in the codebase:
- Introduce
std::atomic<bool> status_update_needed_flag - RT thread sets the flag instead of calling
publish_activity()directly - A timer in the non-RT
executor_thread polls the flag and performs the actual publishing
Is this a known issue? And if a fix is welcome - is the std::atomic flag approach preferred, or would realtime_tools::RealtimeBuffer be more appropriate for the RT-to-non-RT signaling here?
@destogl @saikishor @bmagyar - would appreciate your thoughts on this.