Skip to content

Prevent stale MessageFilter futures after callback race - #986

Open
Parth-Oza wants to merge 1 commit into
ros2:rollingfrom
Parth-Oza:fix/message-filter-future-race
Open

Prevent stale MessageFilter futures after callback race#986
Parth-Oza wants to merge 1 commit into
ros2:rollingfrom
Parth-Oza:fix/message-filter-future-race

Conversation

@Parth-Oza

Copy link
Copy Markdown

Description

MessageFilter::add() currently stores the future returned by waitForTransform() after that call returns. A transform callback running on another thread can complete in the gap between the return and insertion, fail to find its future, and leave the subsequently inserted future stale until clear() or destruction.

This change registers a pending entry before calling waitForTransform(). The callback can erase that entry whether it runs before or after the returned future is installed. Exceptions remove the pending entry, and clear() only cancels entries that contain a realized future.

A deterministic regression test uses a test buffer that invokes the callback from another thread before waitForTransform() returns, then verifies that clear() does not try to cancel the already-completed request.

Fixes #827

Is this user-facing behavior change?

No. This fixes internal future bookkeeping and prevents completed transform requests from remaining registered.

Did you use Generative AI?

Yes. OpenAI Codex assisted with implementation and test construction; the change was reviewed and validated in a clean ROS 2 Rolling container.

Additional Information

Validated on ros:rolling-ros-base (arm64):

  • colcon build --packages-up-to tf2_ros --cmake-args -DBUILD_TESTING=ON -DCMAKE_CXX_FLAGS=-Werror
  • colcon test --packages-select tf2_ros
  • 228 tests/checks reported, 0 errors, 0 failures (56 cppcheck entries skipped because the installed cppcheck version is intentionally disabled by ament)

Signed-off-by: Parth Oza <ozaparthu055@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code has race condition risk

1 participant