Skip to content

Load always the own gz_msgs*.gz_desc first and avoid duplicates#567

Open
j-rivero wants to merge 10 commits intomainfrom
jrivero/gz_msgs_duplicate_fix_main
Open

Load always the own gz_msgs*.gz_desc first and avoid duplicates#567
j-rivero wants to merge 10 commits intomainfrom
jrivero/gz_msgs_duplicate_fix_main

Conversation

@j-rivero
Copy link
Contributor

@j-rivero j-rivero commented Mar 4, 2026

🦟 Bug fix

Fixes #460

Summary

Seems to happen when there are two files (particularly if you two gazebo versions or using GZ_DESCRIPTOR_PATH) that loads the same defined symbols. The loaders loads all files in these directories no matter what files are: https://github.com/gazebosim/gz-msgs/blob/gz-msgs12/core/src/DynamicFactory.cc#L66-L82

When there are different versions of gz-msgs installed we probably want to load first the gz-msgs{MAJOR_VERSION}.gz_desc before others are loaded since it is probably expected by this software to use he default symbols first. Not sure if this fits 100% in all use cases.

The PR does two things:

  • Avoid loading duplicate definitions
  • Always load the own gz_msgs*.gz_desc file first

Checklist

  • Signed all commits for DCO
  • Added a screen capture or video to the PR description that demonstrates the fix (as needed)
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • Updated Bazel files (if adding new files). Created an issue otherwise.
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers
  • Was GenAI used to generate this PR? If so, make sure to add "Generated-by" to your commits. (See this policy for more info.)

Generated-by: Opus 4.6

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by and Generated-by messages.

Backports: If this is a backport, please use Rebase and Merge instead.

Signed-off-by: Jose Luis Rivero <jrivero@honurobotics.com>
Copy link
Collaborator

@caguero caguero left a comment

Choose a reason for hiding this comment

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

Can we perhaps add a test under test/integrations/descriptors.cc that reproduces the issue and fixes it in this branch?

else
{
// Default to loading the descriptor file for this gz-msgs major version if it exists
const std::string ownDescFile =
Copy link
Collaborator

Choose a reason for hiding this comment

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

This constant could live outside the loop.

j-rivero added 2 commits March 4, 2026 18:38
Adds NoDuplicateDescriptors test that reproduces the scenario where the
same .gz_desc file is reachable from multiple paths (e.g. GZ_DESCRIPTOR_PATH
and global share dir), verifying no libprotobuf "File already exists" errors.

Use protobuf log handler to properly detect duplicate descriptor errors

Generated-By: Claude Sonnet 4.6
Signed-off-by: Jose Luis Rivero <jrivero@honurobotics.com>
@j-rivero
Copy link
Contributor Author

j-rivero commented Mar 4, 2026

Can we perhaps add a test under test/integrations/descriptors.cc that reproduces the issue and fixes it in this branch?

Added. Test failing without this branch https://build.osrfoundation.org/job/gz_msgs-ci-pr_any-noble-amd64/173/testReport/(root)/FactoryTest/NoDuplicateDescriptors/

Jose Luis Rivero and others added 2 commits March 4, 2026 19:27
Co-authored-by: Carlos Agüero <caguero@openrobotics.org>
Signed-off-by: Jose Luis Rivero <jrivero@osrfoundation.org>
Signed-off-by: Jose Luis Rivero <jrivero@honurobotics.com>
};

const std::string ownDescFile =
"gz-msgs" + std::to_string(GZ_MSGS_MAJOR_VERSION) + ".gz_desc";
Copy link

Choose a reason for hiding this comment

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

#569 is removing major version numbers from .gz_desc files. Now that we don't support side-by-side installs, would we run into this problem of duplicate .gz_desc files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is right. I've refactored the gz_desc name to be used in all the places 0b7dbd2 .

caguero and others added 5 commits March 12, 2026 16:03
Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org>
After the desc filename was changed to drop the major version number,
refactor the filename into a CMake variable and a C++ preprocessor
define so it is defined in a single place. This also fixes the
DynamicFactory.cc runtime construction which was still using the old
versioned filename format.

Generated-by: Claude Opus 4.6
Signed-off-by: Jose Luis Rivero <jrivero@honurobotics.com>
Signed-off-by: Jose Luis Rivero <jrivero@honurobotics.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

3 participants