Skip to content

Bugfix/rclcpp action UUID rng race condition#3183

Open
iv461 wants to merge 4 commits into
ros2:rollingfrom
iv461:bugfix/rclcpp_action_uuid_rng_race_condition
Open

Bugfix/rclcpp action UUID rng race condition#3183
iv461 wants to merge 4 commits into
ros2:rollingfrom
iv461:bugfix/rclcpp_action_uuid_rng_race_condition

Conversation

@iv461

@iv461 iv461 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #3182

Is this user-facing behavior change?

No

Did you use Generative AI?

No :)

Additional Information

Ivo Ivanov added 2 commits June 24, 2026 21:38
Signed-off-by: Ivo Ivanov <ivo.ivanov@tha.de>
Signed-off-by: Ivo Ivanov <ivo.ivanov@tha.de>
@mergify

mergify Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

Comment thread rclcpp_action/src/client_base.cpp
Comment thread rclcpp_action/src/client_base.cpp Outdated
std::map<int64_t, ResponseCallback> pending_cancel_responses;
std::recursive_mutex cancel_requests_mutex;

std::recursive_mutex goal_id_rng_mutex;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and why dose this need to be recursive mutex?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not need to be, but it prevents deadlocks while having no other disadvantages. So wheneever I'm unsure if there would be an reentrant call to lock from the same thread in the future (if the code changes, gets refactored etc.), I use a reentrant mutex instead of a regular one.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a slight overhead from recursive mutexes. In this case I don't see a deadlock ever happen therefore I would use a normal mutex.

@iv461 iv461 Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is a slight, but insignificant (100 nanoseconds ?) overhead. Therefore I think it is more sensible to just use the reentrant mutex.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage of a reentrant mutex is not reasonable in this case, the lock part is VERY small. Also putting in something that is sub optimal because something can change in the future is not a good argument. This leads to code bloat.

If a future commit manages to add some sort of recursion to this function (which I doubt), then its the job of that commit to also change it to a recursive mutex if needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case currently it is not necessary, sure, and I also can't think of how you would want to call this function recursively. However, my point is that there are no significant disadvantages to adding a recursive mutex.

But by using it, you get the advantage that you cannot produce any deadlocks in the future (of which there were a couple ones here reported in rclcpp that were then resolved by using a recursive mutex).
So overall it has only advantages, no disadvatages, and it's better to be safe than sorry :)

But since you disagree, I will change it back to using a regular mutex :)

Ivo Ivanov added 2 commits June 25, 2026 12:41
… type as the mutex type of course

Signed-off-by: Ivo Ivanov <ivo.ivanov@tha.de>
Signed-off-by: Ivo Ivanov <ivo.ivanov@tha.de>
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.

Data race on the random number generator used in rclcpp_action for creating the UUID

3 participants