Skip to content

Conversation

@alonborn
Copy link
Contributor

@alonborn alonborn commented Apr 26, 2025

Summary

This pull request fixes a bug where rclpy.spin_once() would remove a node from its executor that it didn't add.

Previously, spin_once() unconditionally called executor.remove_node(node) at the end, disconnecting nodes managed by user-created executors (e.g., MultiThreadedExecutor).

This fix tracks whether spin_once() itself added the node, and only removes it if necessary — matching the behavior already used in spin_until_future_complete().


Motivation

Calling rclpy.spin_once() on a node that is part of an existing executor (e.g., for asynchronous callbacks) currently breaks the executor's management, causing nodes to silently stop working.

This fix ensures better safety and makes rclpy utilities more consistent.


Related Issue

It handles a similar issue like #1316


@alonborn alonborn force-pushed the fix-spin-node-removal branch from 64b7cac to 7e848c4 Compare April 26, 2025 08:59
@alonborn
Copy link
Contributor Author

Signed-off-by added via rebase. Ready for review!

@Barry-Xu-2018
Copy link
Contributor

Pulls: #1446
Gist: https://gist.githubusercontent.com/Barry-Xu-2018/b7bf6ed7353257611b68a0995631452b/raw/6dfbd73453f649e5cc3425271d360336ec7ccd89/ros2_rolling.repos
BUILD args: --packages-above-and-dependencies rclpy
TEST args: --packages-above rclpy
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15807

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

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.

i am not opposed to have this fix in general, because we already have the similar fix with #1316.

But I do not think this PR fixes the issue reported on #1445, because MultiThreadedExecutor is still going to be removed in ths 1st spin_once. IMO, this PR or #1316 only works if the application uses get_global_executor to avoid removing the executor.

Note: i mean that the application needs to add executor argument to spin_once.

can you explain what problem are you trying to address here?

@alonborn
Copy link
Contributor Author

Hi @fujitatomoya,
You're absolutely right — this is similar to #1316, but it does not resolve #1445. I've updated the comment above to clarify that.

I originally encountered this unexpected behavior in pymoveit, where calling spin_once caused the executor to lose its node. This fix, combined with explicitly passing the executor to spin_once, allows it to function as expected in that context.

Hope this clears things up — please let me know if anything else is needed.

Thanks again,
Alon

@fujitatomoya
Copy link
Collaborator

@alonborn thanks for the comment.

yeah, for doing resolve the original issue, we need to use executor optional argument with this PR.
anyway this PR does make sense to support that case.

@fujitatomoya
Copy link
Collaborator

Note

to keep the consistency with #1316, we need to backport this to all downstream distros.

@fujitatomoya fujitatomoya merged commit 3414456 into ros2:rolling Apr 29, 2025
3 checks passed
@fujitatomoya
Copy link
Collaborator

@Mergifyio backport kilted jazzy humble

@mergify
Copy link
Contributor

mergify bot commented Apr 29, 2025

mergify bot pushed a commit that referenced this pull request Apr 29, 2025
mergify bot pushed a commit that referenced this pull request Apr 29, 2025
mergify bot pushed a commit that referenced this pull request Apr 29, 2025
fujitatomoya pushed a commit that referenced this pull request May 9, 2025
… attached (#1446) (#1450)

(cherry picked from commit 3414456)

Signed-off-by: Alon <[email protected]>
Co-authored-by: Alon Borenshtein <[email protected]>
fujitatomoya pushed a commit that referenced this pull request May 11, 2025
… attached (#1446) (#1449)

(cherry picked from commit 3414456)

Signed-off-by: Alon <[email protected]>
Co-authored-by: Alon Borenshtein <[email protected]>
fujitatomoya pushed a commit that referenced this pull request May 11, 2025
… attached (#1446) (#1451)

(cherry picked from commit 3414456)

Signed-off-by: Alon <[email protected]>
Co-authored-by: Alon Borenshtein <[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.

3 participants