Skip to content

Fix data race - #498

Merged
urfeex merged 1 commit into
UniversalRobots:masterfrom
urfeex:fix_data_race
May 5, 2026
Merged

Fix data race#498
urfeex merged 1 commit into
UniversalRobots:masterfrom
urfeex:fix_data_race

Conversation

@urfeex

@urfeex urfeex commented May 4, 2026

Copy link
Copy Markdown
Member

While reviewing #496 I realized that we access data from the primary consumer in a hazardous way: Data is stored in shared pointers, while writing and reading those shared pointers is mutex-protected inside the consumer. However, the public access functions expose those shared pointers directly.

This PR instead exposes copies of the buffers upon request.


Note

Medium Risk
Changes thread-safety semantics in PrimaryConsumer by no longer exposing internal shared state and by altering ownership/storage types, which could impact performance or expectations around pointer identity/lifetime.

Overview
PrimaryConsumer no longer exposes its internally-updated state via shared pointers that can be read/written concurrently.

Incoming primary packages are now stored as unique_ptr (and std::optional for VersionInformation), and the public get* accessors return fresh copies (or nullptr when unset) instead of the internal pointer, eliminating a potential data race when callers access data outside the consumer’s mutexes.

Reviewed by Cursor Bugbot for commit d390052. Bugbot is set up for automated code reviews on this repo. Configure here.

@urfeex urfeex added the bugfix label May 4, 2026
@codecov

codecov Bot commented May 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.79%. Comparing base (01cf607) to head (d390052).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #498      +/-   ##
==========================================
- Coverage   76.91%   76.79%   -0.12%     
==========================================
  Files         113      113              
  Lines        6048     6056       +8     
  Branches     2640     2644       +4     
==========================================
- Hits         4652     4651       -1     
- Misses       1060     1071      +11     
+ Partials      336      334       -2     
Flag Coverage Δ
python_scripts 75.90% <ø> (ø)
start_ursim 83.45% <ø> (-1.59%) ⬇️
ur20-latest 72.32% <100.00%> (+0.01%) ⬆️
ur5-3.14.3 72.07% <100.00%> (-0.24%) ⬇️
ur5e-10.11.0 65.79% <100.00%> (-0.44%) ⬇️
ur5e-10.12.0 67.35% <100.00%> (+0.05%) ⬆️
ur5e-10.7.0 65.56% <100.00%> (+0.21%) ⬆️
ur5e-5.9.4 72.95% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@urfeex
urfeex marked this pull request as ready for review May 4, 2026 19:28
@urfeex
urfeex requested a review from a team May 4, 2026 19:28

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default mode and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 98549a8. Configure here.

Comment thread include/ur_client_library/primary/primary_consumer.h
Returning shared pointers to the actual buffers is a risk with regards
to thread safety.

It would probably be even better to use std::optional as an interface
for all of them, but since we've established the shared pointer
interface already, this is imho the next best thing.
@urfeex
urfeex merged commit 4616170 into UniversalRobots:master May 5, 2026
31 of 40 checks passed
@urfeex
urfeex deleted the fix_data_race branch May 5, 2026 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants