Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std::shared_ptr for gz::transport::NodeShared #484

Merged
merged 8 commits into from
Mar 21, 2024

Conversation

azeey
Copy link
Contributor

@azeey azeey commented Mar 18, 2024

🦟 Bug fix

Summary

Currently, NodeShared is never destroyed once it's created. This makes
it hard for writing tests that do not interfere with each other. This
patch uses a reference counted smart pointer (std::shared_ptr) to keep
track of NodeShared instances, so that it gets properly destroyed when
when all Node instances, which themselves contain NodeShared
instances are destroyed.

This was brought up in gazebosim/gz-sim#2334. The INTEGRATION_triggered_publisher test fails reliably in my local tests without this gz-transport PR.

TODO: This is probably not threadsafe. It's possible to lock a mutex before checking the weak_ptr, but that would make the call to NodeSHared::Instance slower than the previous implementation since it was using std::shared_mutex.

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

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

Currently, `NodeShared` is never destroyed once it's created. This makes
it hard for writing tests that do not interfere with each other. This
patch uses a reference counted smart pointer (`std::shared_ptr`) to keep
track of `NodeShared` instances, so that it gets properly destroyed when
when all `Node` instances, which themselves contain `NodeShared`
instances are destroyed.

Signed-off-by: Addisu Z. Taddese <[email protected]>
`Node::Shared` is a private function but it's used in `details/Node.hh`
in templates which means there could be calls to `Node::Shared` embedded
in other libraries. Since we're mainly tracking the number of `Node`
instances, and since `Node::Shared` is private, it's okay to use raw pointers
internal use.

Signed-off-by: Addisu Z. Taddese <[email protected]>
@github-actions github-actions bot added the 🎵 harmonic Gazebo Harmonic label Mar 18, 2024
Signed-off-by: Addisu Z. Taddese <[email protected]>
@azeey azeey marked this pull request as ready for review March 20, 2024 21:28
@azeey azeey requested a review from caguero as a code owner March 20, 2024 21:28
@azeey azeey requested a review from iche033 March 20, 2024 21:29
Copy link

codecov bot commented Mar 20, 2024

Codecov Report

Attention: Patch coverage is 94.44444% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 87.85%. Comparing base (eac2e69) to head (1f2d6f4).
Report is 6 commits behind head on gz-transport13.

Files Patch % Lines
src/NodeShared.cc 91.66% 1 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##           gz-transport13     #484      +/-   ##
==================================================
+ Coverage           87.69%   87.85%   +0.16%     
==================================================
  Files                  59       59              
  Lines                5704     5708       +4     
==================================================
+ Hits                 5002     5015      +13     
+ Misses                702      693       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Addisu Z. Taddese <[email protected]>
Signed-off-by: Addisu Z. Taddese <[email protected]>
Copy link
Contributor

@iche033 iche033 left a comment

Choose a reason for hiding this comment

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

the approach looks good to me.

Maybe @caguero can take a look as well and see if you are ok with this.

@azeey
Copy link
Contributor Author

azeey commented Mar 21, 2024

I can go ahead and merge this, but I think we should make a prerelease and test gz-sim before making a full release. @iche033 or @caguero can I ask one of you to do that please?

@azeey azeey merged commit 42e4210 into gazebosim:gz-transport13 Mar 21, 2024
9 of 10 checks passed
@azeey azeey deleted the shared_ptr_for_nodeshared branch March 21, 2024 19:16
azeey added a commit to azeey/gz-transport that referenced this pull request Apr 1, 2024
azeey added a commit to azeey/gz-transport that referenced this pull request Apr 1, 2024
azeey added a commit that referenced this pull request Apr 2, 2024
This reverts commit 42e4210.

Signed-off-by: Addisu Z. Taddese <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎵 harmonic Gazebo Harmonic
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants