Skip to content

Conversation

@jmachowinski
Copy link
Collaborator

fixes #2678

@mjcarroll we should merge this ASAP and backport to jazzy, to keep the ABI breakage to one release

@jmachowinski
Copy link
Collaborator Author

Pulls: #2745
Gist: https://gist.githubusercontent.com/jmachowinski/3a04e1e78a56e9e964d4ae0ac2ae01fc/raw/ddfb92e12cf7c0ce9b6ecc81882b328e6034df2b/ros2.repos
BUILD args:
TEST args:
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15193

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@mjcarroll mjcarroll self-assigned this Feb 14, 2025
Comment on lines 222 to 224
if(ret) {
break;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(ret) {
break;
}
if (ret) {
break;
}

Comment on lines 244 to 246
if(ret) {
break;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(ret) {
break;
}
if (ret) {
break;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 266 to 268
if(ret) {
break;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(ret) {
break;
}
if (ret) {
break;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed


// wait for both subs to be connected
auto max_end_time = std::chrono::steady_clock::now() + std::chrono::milliseconds(1500);
while((sub1->get_publisher_count() == 0) || (sub2->get_publisher_count() == 0)) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
while((sub1->get_publisher_count() == 0) || (sub2->get_publisher_count() == 0)) {
while ((sub1->get_publisher_count() == 0) || (sub2->get_publisher_count() == 0)) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

// publish some messages, until one subscriber fired. As both subscribers are
// connected to the same topic, they should fire in the same wait.
max_end_time = std::chrono::steady_clock::now() + std::chrono::milliseconds(100);
while(!sub1_works && !sub2_works) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
while(!sub1_works && !sub2_works) {
while (!sub1_works && !sub2_works) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Copy link
Member

@wjwwood wjwwood 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 style fixups

But, I do not believe it fixes #2678, it simply makes it less likely (at least for the multi-threaded executor case or two separate executor case). If async .reset() happens after the executor has acquired the lock, but before it starts executing the callback then you'll still potentially get into a callback after the "owning" class was reset, thus you still need to capture a weak_ptr in the callback.

The right answer to #2678 is documentation, imo.

This pr is still worth doing because it frees up resources more quickly, but it doesn't solve the original problem completely.

@mjcarroll
Copy link
Member

@marcoag FYI we want to get this backported to Jazzy and it does end up with an ABI break.

I think it's important enough to get in, though. Let's coordinate that this gets in before the next sync.

Copy link
Collaborator

@fujitatomoya fujitatomoya 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. just a minor comment.

Janosch Machowinski added 2 commits February 17, 2025 10:35
ros2#2678 reported that the executor
was holding strong references to entities during execution. This commit
adds a regression test for this.

Signed-off-by: Janosch Machowinski <[email protected]>
This fixes a bug, were dropping an entity during a callback would
not prevent further callbacks. Note, there might still be a race
in the case of the mutithreaded executor.

Signed-off-by: Janosch Machowinski <[email protected]>
@jmachowinski jmachowinski force-pushed the executor_strong_reference_fix branch from c8bdffc to c553699 Compare February 17, 2025 09:36
@jmachowinski
Copy link
Collaborator Author

Pulls: #2745
Gist: https://gist.githubusercontent.com/jmachowinski/b0a8898b10d9d067c61f5b40f4940d9b/raw/ddfb92e12cf7c0ce9b6ecc81882b328e6034df2b/ros2.repos
BUILD args:
TEST args:
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15204

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@mjcarroll mjcarroll merged commit 9c493c4 into ros2:rolling Feb 20, 2025
3 checks passed
@marcoag
Copy link
Contributor

marcoag commented Feb 20, 2025

https://github.com/Mergifyio backport jazzy

@mergify
Copy link
Contributor

mergify bot commented Feb 20, 2025

backport jazzy

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Feb 20, 2025
#2678 reported that the executor
was holding strong references to entities during execution. This commit
adds a regression test for this.

* fix(Executor): Don't hold strong references to entities during spin

This fixes a bug, were dropping an entity during a callback would
not prevent further callbacks. Note, there might still be a race
in the case of the mutithreaded executor.

Signed-off-by: Janosch Machowinski <[email protected]>
Co-authored-by: Janosch Machowinski <[email protected]>
(cherry picked from commit 9c493c4)
alsora pushed a commit that referenced this pull request Feb 21, 2025
#2678 reported that the executor
was holding strong references to entities during execution. This commit
adds a regression test for this.

* fix(Executor): Don't hold strong references to entities during spin

This fixes a bug, were dropping an entity during a callback would
not prevent further callbacks. Note, there might still be a race
in the case of the mutithreaded executor.

Signed-off-by: Janosch Machowinski <[email protected]>
Co-authored-by: Janosch Machowinski <[email protected]>
(cherry picked from commit 9c493c4)

Co-authored-by: Janosch Machowinski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subscriber is being held when another subscriber callback is being called

7 participants