From f4b8d43a681a908ce22b63ece3a86ab5b198e760 Mon Sep 17 00:00:00 2001 From: Lanze Liu <86434077+liulanze@users.noreply.github.com> Date: Tue, 13 Oct 2026 20:33:18 -0700 Subject: [PATCH] [Bugfix] Keep force-killing the process tree when a child exits mid-walk (#59984) Signed-off-by: Lanze Liu Co-authored-by: Ning Xie --- tests/utils_/test_system_utils.py | 30 ++++++++++++++++++++++++++++++ vllm/utils/system_utils.py | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/utils_/test_system_utils.py b/tests/utils_/test_system_utils.py index 55ed35eeb5..ef95bd7c36 100644 --- a/tests/utils_/test_system_utils.py +++ b/tests/utils_/test_system_utils.py @@ -4,10 +4,15 @@ import contextlib import io import os +import signal +import subprocess import sys import tempfile from pathlib import Path +import psutil + +from vllm.utils import system_utils from vllm.utils.system_utils import ( _maybe_force_spawn, suppress_stdout, @@ -48,3 +53,28 @@ def test_suppress_stdout_keeps_stderr_when_sys_stdout_is_stderr(capfd, monkeypat out, err = capfd.readouterr() assert "c library output" not in out assert "error message" in err + + +def test_kill_process_tree_skips_child_that_exits_mid_walk(monkeypatch): + sleep = [sys.executable, "-c", "import time; time.sleep(60)"] + target, *children = procs = [subprocess.Popen(sleep) for _ in range(4)] + try: + # List the children while they are alive, then let one exit and be + # reaped before the walk reaches it, so psutil's name() raises. + listed = [psutil.Process(p.pid) for p in children] + children[1].terminate() + children[1].wait(timeout=10) + monkeypatch.setattr( + psutil.Process, "children", lambda self, recursive=False: listed + ) + + system_utils.kill_process_tree(target.pid) + + # The exited child died from our SIGTERM; the rest were SIGKILLed. + assert children[1].returncode == -signal.SIGTERM + for p in (children[0], children[2], target): + assert p.wait(timeout=10) == -signal.SIGKILL + finally: + for p in procs: + p.kill() + p.wait() diff --git a/vllm/utils/system_utils.py b/vllm/utils/system_utils.py index a15dbf3c6c..71947609bf 100644 --- a/vllm/utils/system_utils.py +++ b/vllm/utils/system_utils.py @@ -221,7 +221,7 @@ def kill_process_tree(pid: int): # Send SIGKILL to all children first for child in children: - with contextlib.suppress(ProcessLookupError): + with contextlib.suppress(ProcessLookupError, psutil.NoSuchProcess): logger.warning( "[shutdown] force killing sub process %s pid %d", child.name(),