WaitForTopics blocks interpreter exit if shutdown() is never called
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 53/100
Research direction
Start by reading WaitForTopics in launch_testing_ros/wait_for_topics.py, especially __init__, _spin_handle_external_shutdown, shutdown(), and the context manager. Check how the thread and rclpy executor behave during Python interpreter finalization, then choose and validate a cleanup approach against the documented manual wait()/shutdown() usage. Done means a failed wait() cannot leave a thread that prevents pytest from exiting, without causing a crash during shutdown.
Written by the indexing model from the issue text.
Description
Description
WaitForTopics.__init__ starts a non-daemon thread that spins the executor, and only WaitForTopics.shutdown() stops it. If a caller never reaches shutdown() (most commonly because an assertion between wait() and shutdown() fails), the thread keeps spinning after the test finishes. The interpreter then blocks forever in threading._shutdown waiting for it.
Under pytest this happens after the session has finished, so pytest-timeout can't catch it. The process just never exits, and in CI that means the build runs until the global job timeout (600 minutes on ci.ros2.org).
This is the documented "Method 2" usage pattern:
wait_for_topics = WaitForTopics(topic_list, timeout=5.0)
assert wait_for_topics.wait() # if this fails, shutdown() never runs
...
wait_for_topics.shutdown()
Evidence
Found while chasing launch_testing_ros hangs on ci.ros2.org (e.g. nightly_linux-aarch64_debug #3744). With the launch tests repeated 51x on Debug builds (ci_launcher 20974), the faulthandler watchdog from #591 dumped this at exit on Linux, aarch64 and RHEL. There was one such thread per failed wait_for_topic_launch_test repeat (2, 1 and 6 respectively):
Thread 0x... [Thread-526 (_sp] (most recent call first):
File ".../rclpy/executors.py", line 1011 in _wait_for_ready_callbacks
...
File ".../rclpy/executors.py", line 518 in spin
File ".../launch_testing_ros/wait_for_topics.py", line 94 in _spin_handle_external_shutdown
...
Thread 0x... [python3] (most recent call first):
File "/usr/lib/python3.14/threading.py", line 1583 in _shutdown
#591 fixes launch_testing_ros's own test (shutdown() in finally, longer timeouts), but any user test that uses WaitForTopics the same way can still hang its CI job.
Possible fixes
- Make the spin thread a daemon (
daemon=True). This is the simplest. The thread is normally blocked inrcl_waitwith the GIL released, so the interpreter can exit past it. We need to check that rclpy doesn't crash at finalization with a daemon thread insidespin()and an un-shut-down context. - Shut down before Python waits for threads. Register
shutdown()to run before the interpreter joins non-daemon threads.threading._register_atexitdoes exactly that, but it's private API. Plainatexitruns too late, after the join. - In either case, consider having
wait()/__enter__document or enforce cleanup. For example, encourage the context-manager form, which already callsshutdown()on failure, over manualwait()/shutdown()in the docstring.
- Dominant language
- Python
- Stars
- 84
- Forks
- 115
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ros2/launch_ros
-
yaml.add_representer in Node._create_params_file_from_dict mutates global yaml.Dumper, corrupting unrelated yaml.dump() calls in the same processPossibly taken @dlanov claimed this 73 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
ros2/launch_ros#571 · 1 comment ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 48/100
ros2/launch_ros#595 ·
-
Unable to specifiy type of parameter when using `set_parameter`Possibly taken @SuperJappie08 claimed this 7 days ago. Openbug
Difficulty 3/5 1-2 days Newbie friendliness 55/100
ros2/launch_ros#593 · 1 comment · 1 assignee ·
-
0.29.9 introduces a regression on lyricalPossibly taken A pull request linked to this issue is open or already merged. Openbug
Difficulty 3/5 1-2 days Newbie friendliness 55/100
ros2/launch_ros#550 ·
-
Feature request: ros2 launch --dump-params to statically export resolved node parametersPossibly taken @IdiotCoffee claimed this 56 days ago. Openenhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
ros2/launch_ros#549 · 3 comments · 1 reaction ·
Similar issues
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gke-labs/kube-agents#7441 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
bug confirmed issue
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
open-webui/open-webui#35142 · 1 comment ·
Maintainers usually reply within 1 day