Skip to content

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented Jan 28, 2026

Description

This PR fixes a bug where DataReader was incorrectly using history.depth instead of max_samples_per_instance when depth > max_samples_per_instance.

Current Behavior (Bug)

When a DataReader is configured with:

  • history.depth = 10
  • max_samples_per_instance = 5

The QoS validation correctly warns:

HISTORY DEPTH '10' is inconsistent with max_samples_per_instance: '5'. 
Effectively using max_samples_per_instance as depth.

However, the DataReader was actually storing 10 samples (using depth) instead of 5 (using max_samples_per_instance), making the warning misleading.

Root Cause

The bug existed in three locations:

  1. DataReaderHistory constructor: For NO_KEY topics, max_samples_per_instance was being overwritten with max_samples, destroying the user's QoS setting
  2. DataReaderHistory::received_change_keep_last: Was checking instance_changes.size() < depth instead of instance_changes.size() < min(depth, max_samples_per_instance)
  3. DataReaderHistory::completed_change_keep_last: Same issue for fragmented samples

Changes

  • Fixed all three locations to use min(history.depth, max_samples_per_instance) as the effective limit
  • Updated DataWriterHistory::to_history_attributes for consistency in memory allocation
  • Added unit tests covering:
    • NO_KEY topics (critical case where constructor was overwriting QoS)
    • WITH_KEY topics

Impact

This fix ensures the DataReader behavior matches the documented QoS warning message. Applications relying on max_samples_per_instance to limit memory usage will now work correctly.

@Mergifyio backport 3.4.x 3.2.x 2.14.x

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.
  • N/A 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.
  • N/A 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.
  • N/A: 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.

This is an automatic backport of pull request #6228 done by [Mergify](https://mergify.com).

#6228)

* Fix DataReader history enforcement to respect max_samples_per_instance

Signed-off-by: Raül <[email protected]>

* Take into account LENGTH_UNLIMITED, go back to max_samples allocation and add tests accordingly

Signed-off-by: Raül <[email protected]>

* Uncrustify

Signed-off-by: Raül <[email protected]>

* More uncrustify

Signed-off-by: Raül <[email protected]>

* Refactor history depth vs mspi tests

Signed-off-by: Raül <[email protected]>

* Uncrustify

Signed-off-by: Raül <[email protected]>

* Update src/cpp/fastdds/publisher/DataWriterHistory.cpp

Co-authored-by: Miguel Company <[email protected]>
Signed-off-by: Raül Ojeda Gandia <[email protected]>

* Refactor tests and add keyed keep_all tests

Signed-off-by: Raül <[email protected]>

* Update src/cpp/fastdds/publisher/DataWriterHistory.cpp

Co-authored-by: Miguel Company <[email protected]>
Signed-off-by: Raül Ojeda Gandia <[email protected]>

* New uncrustify

Signed-off-by: Raül <[email protected]>

---------

Signed-off-by: Raül <[email protected]>
Signed-off-by: Raül Ojeda Gandia <[email protected]>
Co-authored-by: Miguel Company <[email protected]>
(cherry picked from commit 30b6351)

# Conflicts:
#	src/cpp/fastdds/publisher/DataWriterHistory.cpp
#	src/cpp/fastdds/publisher/DataWriterImpl.cpp
#	src/cpp/fastdds/subscriber/DataReaderImpl.cpp
#	test/mock/rtps/PublisherHistory/fastdds/publisher/DataWriterHistory.hpp
#	test/unittest/dds/subscriber/DataReaderTests.cpp
@mergify mergify bot added the conflicts Backport PR wich git cherry pick failed label Jan 28, 2026
@mergify
Copy link
Contributor Author

mergify bot commented Jan 28, 2026

Cherry-pick of 30b6351 has failed:

On branch mergify/bp/2.14.x/pr-6228
Your branch is up to date with 'origin/2.14.x'.

You are currently cherry-picking commit 30b63511d.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   src/cpp/fastdds/subscriber/history/DataReaderHistory.cpp
	modified:   src/cpp/rtps/history/HistoryAttributesExtension.hpp

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/cpp/fastdds/publisher/DataWriterHistory.cpp
	both modified:   src/cpp/fastdds/publisher/DataWriterImpl.cpp
	both modified:   src/cpp/fastdds/subscriber/DataReaderImpl.cpp
	both modified:   test/mock/rtps/PublisherHistory/fastdds/publisher/DataWriterHistory.hpp
	both modified:   test/unittest/dds/subscriber/DataReaderTests.cpp

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@emiliocuestaf emiliocuestaf removed the conflicts Backport PR wich git cherry pick failed label Jan 29, 2026
@emiliocuestaf emiliocuestaf requested review from richiprosima and removed request for richiprosima January 29, 2026 06:28
@github-actions github-actions bot added the ci-pending PR which CI is running label Jan 29, 2026
@mergify
Copy link
Contributor Author

mergify bot commented Jan 29, 2026

🧪 CI Insights

Here's what we observed from your CI run for 55b37db.

❌ Job Failures

Pipeline Job Health on 2.14.x Retries 🔍 CI Insights 📄 Logs
Fast-DDS MacOS CI mac-ci / fastdds_test () Unknown 0 View View
Fast-DDS Windows CI windows-ci / reusable-windows-ci (RelWithDebInfo, v142) Unknown 0 View View
windows-ci / reusable-windows-ci (RelWithDebInfo, v143) Unknown 0 View View

Signed-off-by: Emilio Cuesta <[email protected]>
@emiliocuestaf emiliocuestaf removed the ci-pending PR which CI is running label Jan 30, 2026
@emiliocuestaf emiliocuestaf requested review from richiprosima and removed request for richiprosima January 30, 2026 12:30
@github-actions github-actions bot added the ci-pending PR which CI is running label Jan 30, 2026
Signed-off-by: Emilio Cuesta <[email protected]>
@emiliocuestaf emiliocuestaf removed the ci-pending PR which CI is running label Jan 30, 2026
@emiliocuestaf emiliocuestaf requested review from richiprosima and removed request for richiprosima January 30, 2026 12:31
@github-actions github-actions bot added the ci-pending PR which CI is running label Jan 30, 2026
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.

3 participants