Skip to content

Potential RT safety concern: publish_activity() called from update() loop with mutex acquisition #3145

@shlok-mehndiratta

Description

@shlok-mehndiratta

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:

  1. Introduce std::atomic<bool> status_update_needed_ flag
  2. RT thread sets the flag instead of calling publish_activity() directly
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions