Skip to content

[24604] Fix minor dataraces#6422

Open
ZakariaTalbi wants to merge 17 commits into
masterfrom
tsan/reader-locator-race
Open

[24604] Fix minor dataraces#6422
ZakariaTalbi wants to merge 17 commits into
masterfrom
tsan/reader-locator-race

Conversation

@ZakariaTalbi

@ZakariaTalbi ZakariaTalbi commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Description

The goal of this PR is to solve some of the minor dataraces that appear when running under the TSAN meta.

LocalReader datarace:

ReaderLocator::local_reader_ was being read in intraprocess_heartbeat and intraprocess_delivery without holding the writer's mutex, while ReaderLocator::stop() reset it under that same mutex, causing a data race. Fixed by acquiring mp_mutex before calling local_reader() in both methods.

As this was already being reported by TSAN when running the DDSBasic_WarningOnDelete_Test, no new tests have been added.

Contributor Checklist

  • Commit messages follow the project guidelines.
  • The code follows the style guidelines of this project.
  • [❌] Tests that thoroughly check the new feature have been added/Regression tests checking the bug and its fix have been added; the added tests pass locally
  • Any new/modified methods have been properly documented using Doxygen.
  • Any new configuration API has an equivalent XML API (with the corresponding XSD extension)
  • Changes are backport compatible: they do NOT break ABI nor change library core behavior.
  • Changes are API compatible.
  • New feature has been added to the versions.md file (if applicable).
  • New feature has been documented/Current behavior is correctly described in the documentation.
  • Applicable backports have been included in the description.

Reviewer Checklist

  • The PR has a milestone assigned.
  • The title and description correctly express the PR's purpose.
  • Check contributor checklist is correct.
  • If this is a critical bug fix, backports to the critical-only supported branches have been requested.
  • Check CI results: changes do not issue any warning.
  • Check CI results: failing tests are unrelated with the changes.

Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
@ZakariaTalbi ZakariaTalbi changed the title #24604 Protect ReaderLocator local_reader_ access with writer mutex [24604] Protect ReaderLocator local_reader_ access with writer mutex Jun 8, 2026
@ZakariaTalbi ZakariaTalbi changed the title [24604] Protect ReaderLocator local_reader_ access with writer mutex [24604] Fix minor dataraces Jun 8, 2026
Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
@ZakariaTalbi
ZakariaTalbi requested a review from richiprosima June 8, 2026 14:15
@github-actions github-actions Bot added the ci-pending PR which CI is running label Jun 8, 2026
Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
…ith atomic

Signed-off-by: Zakaria Talbi Lalmi <zakariatalbi@eprosima.com>
@ZakariaTalbi
ZakariaTalbi requested review from richiprosima and removed request for richiprosima June 16, 2026 09:16

@MiguelCompany MiguelCompany left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Apart from my comments below, please check whether changes made in PubSubReader and PubSubWriter also apply to PubSubWriterReader and/or PubSubParticipant

Comment on lines +70 to +78
// TODO: same issue as get_raw_status, reference escapes the lock.
return mask_;
}

const StatusMask& StatusConditionImpl::get_raw_status() const
{
std::lock_guard<std::mutex> guard(mutex_);
// TODO: returning a reference to a mutex-protected member that escapes the lock is a data race.
// Fix requires changing the return type to StatusMask (by value), which is an API break.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Change these into FASTDDS_TODO_BEFORE(4, 0, ...)


unsigned int get_participants_matched() const
{
std::unique_lock<std::mutex> lock(mutexDiscovery_);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
std::unique_lock<std::mutex> lock(mutexDiscovery_);
std::lock_guard<std::mutex> lock(mutexDiscovery_);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Take the chance to also change it in other places.


unsigned int get_participants_matched() const
{
std::unique_lock<std::mutex> lock(mutexDiscovery_);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
std::unique_lock<std::mutex> lock(mutexDiscovery_);
std::lock_guard<std::mutex> lock(mutexDiscovery_);


unsigned int get_participants_matched()
{
std::unique_lock<std::mutex> lock(mutexDiscovery_);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
std::unique_lock<std::mutex> lock(mutexDiscovery_);
std::lock_guard<std::mutex> lock(mutexDiscovery_);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-pending PR which CI is running

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants