Skip to content

Fix LaunchService._is_idle() to consider active asyncio background tasks - #996

Open
wjwwood wants to merge 1 commit into
rollingfrom
wjwwood/fix_is_idle_background_tasks
Open

Fix LaunchService._is_idle() to consider active asyncio background tasks#996
wjwwood wants to merge 1 commit into
rollingfrom
wjwwood/fix_is_idle_background_tasks

Conversation

@wjwwood

@wjwwood wjwwood commented Aug 14, 2026

Copy link
Copy Markdown
Member

Description

This PR updates LaunchService._is_idle() to account for active asyncio.Task instances running in the event loop that are not tracked as entity/completion futures.

When an error occurs during launch description evaluation (e.g. invalid action/node argument or failure during execute()), previously launched processes might still be in the middle of asynchronous setup. When LaunchService._is_idle() exited immediately, these subprocesses were orphaned because the main event loop exited before their ProcessStarted / OnShutdown handlers could be processed.

This addresses the deadlock issue found in #901 by excluding LaunchService's internal event-processing task (__process_one_event_task) and main task (__this_task) when inspecting active tasks.

Fixes #747
Supersedes #901

Is this user-facing behavior change?

No. Child processes started before an exception during launch are now reliably terminated during shutdown rather than orphaned.

Did you use Generative AI?

Yes, Gemini 3.7 Flash.

@mergify

mergify Bot commented Aug 14, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

Considers non-internal active asyncio tasks in `LaunchService._is_idle()`
to ensure background tasks (such as asynchronous process execution) have a
chance to complete and be managed during shutdown, rather than terminating
prematurely and leaving orphaned child processes.

Fixes #747
Reuses test case from #901

Co-authored-by: MegaIng <26136419+MegaIng@users.noreply.github.com>
Signed-off-by: William Woodall <wjwwood@google.com>
@wjwwood

wjwwood commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

Pulls: #996
Gist: https://gist.githubusercontent.com/wjwwood/288c8f9263d56a1a5fd0d701ca88be84/raw/1ea607e022cf7302810915cdd0fdf3ec01f8672b/ros2.repos
BUILD args: --packages-above-and-dependencies launch
TEST args: --packages-above launch
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/20084

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

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.

Launch doesn't stop running nodes when exception thrown

1 participant