Skip to content

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented Oct 31, 2025

🦟 Bug fix

Fixes #701

Summary

According to #701, checking an environment variable every time that we're inside the Version() function might cause a crash. This patch only checks the environment variable once.

There's some behavior change here because you cannot change the value of the environment variable in the middle of a gz-transport session anymore. I think it's probably a good idea not allowing that but I can be convinced otherwise.

Checklist

  • Signed all commits for DCO
  • 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)
  • 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.)

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.


This is an automatic backport of pull request #731 done by Mergify.

* Only check GZ_TRANSPORT_TOPIC_STATISTICS once

Signed-off-by: Carlos Agüero <[email protected]>
(cherry picked from commit 815b417)
@mergify mergify bot requested a review from caguero as a code owner October 31, 2025 16:04
@github-actions github-actions bot added the 🪵 jetty Gazebo Jetty label Oct 31, 2025
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
src/Discovery.hh Outdated
/// \brief Wire protocol version. Bump up the version number if you modify
/// the wire protocol (for discovery or message/service exchange).
/// \TODO(caguero): Remove static in Gazebo K.
private: static uint8_t wireVersion;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private: static uint8_t wireVersion;
private: static inline uint8_t wireVersion = 10;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done in ac61c48.

src/Discovery.hh Outdated
Comment on lines 1769 to 1773
/// \brief wireVersion definition.
/// \TODO(caguero): Remove in Gazebo K.
template<typename Pub>
uint8_t Discovery<Pub>::wireVersion = 10u;

Copy link
Contributor

Choose a reason for hiding this comment

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

This can be removed if we use static inline as suggested.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks, removed in ac61c48.

// Update the wire version if GZ_TRANSPORT_TOPIC_STATISTICS is set.
std::string gzStats;
if (env("GZ_TRANSPORT_TOPIC_STATISTICS", gzStats) && gzStats == "1")
this->wireVersion += 100;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we be sure that Discovery is constructed only once?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's constructed twice, one for msgs and one for services here.

Are you thinking on race conditions? If so, they're constructed in sequence, so I think we should be good.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I'm concerned that the since wireVersion is a static variable, every construction of the same template type would increment the wire version. I guess I'm not sure why it needs to be static at all if each instance will end up computing the wireVersion anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The reason to make it static is to preserve ABI.

Signed-off-by: Carlos Agüero <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🪵 jetty Gazebo Jetty

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

Occasional crash on startup in discovery

3 participants