Repository navigation
fix(ros2): stop connector executor without hanging on shutdown - #889
Open
maciejmajek wants to merge 3 commits into
Open
maciejmajek wants to merge 3 commits into
maciejmajek wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #889 +/- ##
=======================================
Coverage ? 76.42%
=======================================
Files ? 83
Lines ? 3674
Branches ? 0
=======================================
Hits ? 2808
Misses ? 866
Partials ? 0 ☔ View full report in Codecov by Harness. |
ROS2BaseConnector.shutdown() could block forever joining the spin thread. Executor.shutdown() from another thread can leave spin() waiting on an empty wait set. Spin with spin_once(timeout_sec=0.1) and a stop flag, stop the thread first and destroy the node last. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
maciejmajek
force-pushed
the
fix/connector-shutdown-hang-v2
branch
from
November 6, 2026 16:28
c2e123c to
c4e30ec
Compare
spin_until_future_complete() wakes the executor as soon as the future completes, so shutdown is immediate and idle connectors do not poll. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
ROS2BaseConnector.shutdown()sometimes blocks forever. Seen in CI on self-hosted and GitHub-hosted runners: the main thread waits inself._thread.join()and never returns.Proposed Changes
Executor.spin()in a thread and stops it withExecutor.shutdown()from another thread.shutdown()destroys the executor's guard conditions and clears its nodes. If the spin thread is building its wait set at that moment, it waits on an empty set with no timeout, forever.executor.spin_until_future_complete(self._stop_spinning).shutdown()completes the future, which wakes the executor (rclpy addsfuture.add_done_callback(lambda x: self.wake())). The thread returns, then the executor is shut down with nobody spinning it.shutdown()order: stop and join the thread, then TF listener, action and topic APIs, executor, and destroy the node last. Before, the node was destroyed while the executor could still use it.rai_coreto 2.13.1.Behaviour for existing code
spin()andspin_until_future_complete()both run_spin_once_implper iteration. The only extra work is afuture.done()check on wake.spin().rclpy.spin(connector.node)(rai_semap,rai_perceptiondetection publisher) move the node to the global executor, same as today. The connector thread then waits on an empty executor and still wakes on shutdown.Issues
tests/tools/ros2/test_topic_tools.pyduring connector teardown.Testing
test_ros2_connector_shutdown_does_not_hang: 100 connector create and shutdown cycles, 60 s limit.MultiThreadedExecutor, node with timer and 40 subscriptions, 4 busy threads, 4 CPUs:MultiThreadedExecutor): old and new are equal within noise on both distros.