Skip to content

Comments

[23974] Fix DataReader history enforcement to respect max_samples_per_instance#6228

Merged
MiguelCompany merged 12 commits into3.4.xfrom
hotfix/depth_vs_max_spi
Jan 28, 2026
Merged

[23974] Fix DataReader history enforcement to respect max_samples_per_instance#6228
MiguelCompany merged 12 commits into3.4.xfrom
hotfix/depth_vs_max_spi

Conversation

@raulojeda22
Copy link
Contributor

@raulojeda22 raulojeda22 commented Dec 31, 2025

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.

@github-actions github-actions bot added the ci-pending PR which CI is running label Dec 31, 2025
@mergify
Copy link
Contributor

mergify bot commented Dec 31, 2025

🧪 CI Insights

Here's what we observed from your CI run for 5b0f1ee.

❌ Job Failures

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

@raulojeda22 raulojeda22 force-pushed the hotfix/depth_vs_max_spi branch from 37561c7 to 5259203 Compare January 7, 2026 15:30
@rsanchez15 rsanchez15 requested review from juanlofer-eprosima and removed request for juanlofer-eprosima January 8, 2026 08:02
@MiguelCompany MiguelCompany added this to the v3.5.0 milestone Jan 12, 2026
@rsanchez15 rsanchez15 changed the base branch from master to 3.4.x January 20, 2026 08:08
@rsanchez15 rsanchez15 modified the milestones: v3.5.0, v3.4.2 Jan 20, 2026
@raulojeda22 raulojeda22 force-pushed the hotfix/depth_vs_max_spi branch from 5259203 to d7266a4 Compare January 20, 2026 10:53
@raulojeda22 raulojeda22 requested review from richiprosima and removed request for richiprosima January 20, 2026 10:57
Copy link
Member

@MiguelCompany MiguelCompany left a comment

Choose a reason for hiding this comment

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

Apart from the comment below, remember to clarify the documentation (i.e. do a partial backport of eProsima/Fast-DDS-docs#1188)

Signed-off-by: Raül <raulojeda@eprosima.com>
… and add tests accordingly

Signed-off-by: Raül <raulojeda@eprosima.com>
Signed-off-by: Raül <raulojeda@eprosima.com>
Signed-off-by: Raül <raulojeda@eprosima.com>
Signed-off-by: Raül <raulojeda@eprosima.com>
Signed-off-by: Raül <raulojeda@eprosima.com>
@raulojeda22 raulojeda22 force-pushed the hotfix/depth_vs_max_spi branch from 348cd88 to 0b4a87c Compare January 27, 2026 06:34
@raulojeda22 raulojeda22 requested review from richiprosima and removed request for richiprosima January 27, 2026 06:37
@raulojeda22 raulojeda22 changed the title [#23974] Fix DataReader history enforcement to respect max_samples_per_instance [23974] Fix DataReader history enforcement to respect max_samples_per_instance Jan 27, 2026
raulojeda22 and others added 3 commits January 27, 2026 09:24
Co-authored-by: Miguel Company <miguelcompany@eprosima.com>
Signed-off-by: Raül Ojeda Gandia <raulojeda@eprosima.com>
Signed-off-by: Raül <raulojeda@eprosima.com>
MiguelCompany
MiguelCompany previously approved these changes Jan 27, 2026
Copy link
Member

@MiguelCompany MiguelCompany left a comment

Choose a reason for hiding this comment

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

LGTM with green CI

@raulojeda22 raulojeda22 requested review from richiprosima and removed request for richiprosima January 27, 2026 10:35
raulojeda22 and others added 3 commits January 27, 2026 12:25
Co-authored-by: Miguel Company <miguelcompany@eprosima.com>
Signed-off-by: Raül Ojeda Gandia <raulojeda@eprosima.com>
Signed-off-by: Raül <raulojeda@eprosima.com>
@MiguelCompany MiguelCompany merged commit 30b6351 into 3.4.x Jan 28, 2026
24 of 28 checks passed
@MiguelCompany MiguelCompany deleted the hotfix/depth_vs_max_spi branch January 28, 2026 07:20
@MiguelCompany
Copy link
Member

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

@mergify
Copy link
Contributor

mergify bot commented Jan 28, 2026

backport 3.4.x 3.2.x 2.14.x

✅ Backports have been created

Details
  • Backport to branch 3.4.x completed

No pull request needed: No commits between 3.4.x and mergify/bp/3.4.x/pr-6228

Cherry-pick of 30b6351 has failed:

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

You are currently cherry-picking commit 30b63511.
  (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/publisher/DataWriterHistory.cpp
	modified:   src/cpp/fastdds/publisher/DataWriterImpl.cpp
	modified:   src/cpp/fastdds/subscriber/DataReaderImpl.cpp
	modified:   src/cpp/fastdds/subscriber/history/DataReaderHistory.cpp
	modified:   src/cpp/rtps/history/HistoryAttributesExtension.hpp
	modified:   test/mock/dds/DataWriterHistory/fastdds/publisher/DataWriterHistory.hpp

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	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

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

mergify bot pushed a commit that referenced this pull request Jan 28, 2026
#6228)

* Fix DataReader history enforcement to respect max_samples_per_instance

Signed-off-by: Raül <raulojeda@eprosima.com>

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

Signed-off-by: Raül <raulojeda@eprosima.com>

* Uncrustify

Signed-off-by: Raül <raulojeda@eprosima.com>

* More uncrustify

Signed-off-by: Raül <raulojeda@eprosima.com>

* Refactor history depth vs mspi tests

Signed-off-by: Raül <raulojeda@eprosima.com>

* Uncrustify

Signed-off-by: Raül <raulojeda@eprosima.com>

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

Co-authored-by: Miguel Company <miguelcompany@eprosima.com>
Signed-off-by: Raül Ojeda Gandia <raulojeda@eprosima.com>

* Refactor tests and add keyed keep_all tests

Signed-off-by: Raül <raulojeda@eprosima.com>

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

Co-authored-by: Miguel Company <miguelcompany@eprosima.com>
Signed-off-by: Raül Ojeda Gandia <raulojeda@eprosima.com>

* New uncrustify

Signed-off-by: Raül <raulojeda@eprosima.com>

---------

Signed-off-by: Raül <raulojeda@eprosima.com>
Signed-off-by: Raül Ojeda Gandia <raulojeda@eprosima.com>
Co-authored-by: Miguel Company <miguelcompany@eprosima.com>
(cherry picked from commit 30b6351)

# Conflicts:
#	test/unittest/dds/subscriber/DataReaderTests.cpp
mergify bot pushed a commit that referenced this pull request Jan 28, 2026
#6228)

* Fix DataReader history enforcement to respect max_samples_per_instance

Signed-off-by: Raül <raulojeda@eprosima.com>

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

Signed-off-by: Raül <raulojeda@eprosima.com>

* Uncrustify

Signed-off-by: Raül <raulojeda@eprosima.com>

* More uncrustify

Signed-off-by: Raül <raulojeda@eprosima.com>

* Refactor history depth vs mspi tests

Signed-off-by: Raül <raulojeda@eprosima.com>

* Uncrustify

Signed-off-by: Raül <raulojeda@eprosima.com>

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

Co-authored-by: Miguel Company <miguelcompany@eprosima.com>
Signed-off-by: Raül Ojeda Gandia <raulojeda@eprosima.com>

* Refactor tests and add keyed keep_all tests

Signed-off-by: Raül <raulojeda@eprosima.com>

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

Co-authored-by: Miguel Company <miguelcompany@eprosima.com>
Signed-off-by: Raül Ojeda Gandia <raulojeda@eprosima.com>

* New uncrustify

Signed-off-by: Raül <raulojeda@eprosima.com>

---------

Signed-off-by: Raül <raulojeda@eprosima.com>
Signed-off-by: Raül Ojeda Gandia <raulojeda@eprosima.com>
Co-authored-by: Miguel Company <miguelcompany@eprosima.com>
(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
MiguelCompany pushed a commit that referenced this pull request Feb 4, 2026
#6228) (#6285)

* Fix DataReader history enforcement to respect max_samples_per_instance (#6228)

* Fix DataReader history enforcement to respect max_samples_per_instance

Signed-off-by: Raül <raulojeda@eprosima.com>

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

Signed-off-by: Raül <raulojeda@eprosima.com>

* Uncrustify

Signed-off-by: Raül <raulojeda@eprosima.com>

* More uncrustify

Signed-off-by: Raül <raulojeda@eprosima.com>

* Refactor history depth vs mspi tests

Signed-off-by: Raül <raulojeda@eprosima.com>

* Uncrustify

Signed-off-by: Raül <raulojeda@eprosima.com>

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

Co-authored-by: Miguel Company <miguelcompany@eprosima.com>
Signed-off-by: Raül Ojeda Gandia <raulojeda@eprosima.com>

* Refactor tests and add keyed keep_all tests

Signed-off-by: Raül <raulojeda@eprosima.com>

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

Co-authored-by: Miguel Company <miguelcompany@eprosima.com>
Signed-off-by: Raül Ojeda Gandia <raulojeda@eprosima.com>

* New uncrustify

Signed-off-by: Raül <raulojeda@eprosima.com>

---------

Signed-off-by: Raül <raulojeda@eprosima.com>
Signed-off-by: Raül Ojeda Gandia <raulojeda@eprosima.com>
Co-authored-by: Miguel Company <miguelcompany@eprosima.com>
(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

* Fix conflicts and compilation issues

Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>

* Fix wrong backports

Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>

* Uncrustify

Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>

* Fix failing test

Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>

* Refactor pool config in DataWriterImpl

Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>

* Uncrustify

Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>

---------

Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>
Co-authored-by: Raül Ojeda Gandia <raulojeda@eprosima.com>
Co-authored-by: Emilio Cuesta <emiliocuesta@eprosima.com>
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