From d5dad0c3033b47557d465a6e05d8887c1e6c9341 Mon Sep 17 00:00:00 2001 From: bhuvan-somisetty Date: Tue, 6 Oct 2026 19:48:18 +0530 Subject: [PATCH] fix: check concorekill PIDs without wmic wmic is gone on recent Windows 11, and the generated concorekill.bat aborted at that line so nothing got killed. Look up the command line with Get-CimInstance instead and match it with findstr. --- concore.java | 2 +- concore.py | 2 +- tests/test_concore.py | 29 ++++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/concore.java b/concore.java index c5178fe..94f92cd 100644 --- a/concore.java +++ b/concore.java @@ -93,7 +93,7 @@ private static void writeKillScript() { script += " exit /b 0\r\n"; script += ")\r\n"; script += "for /f \"usebackq tokens=*\" %%p in (\"%~dp0" + regName + "\") do (\r\n"; - script += " wmic process where \"ProcessId=%%p\" get CommandLine /value 2>nul | find /i \"concore\" >nul\r\n"; + script += " powershell -NoProfile -Command \"(Get-CimInstance Win32_Process -Filter 'ProcessId=%%p').CommandLine\" 2>nul | findstr /i \"concore\" >nul\r\n"; script += " if not errorlevel 1 (\r\n"; script += " echo Killing concore process %%p\r\n"; script += " taskkill /F /PID %%p >nul 2>&1\r\n"; diff --git a/concore.py b/concore.py index 1ed220f..01c4e0f 100644 --- a/concore.py +++ b/concore.py @@ -118,7 +118,7 @@ def _write_kill_script(): script += " exit /b 0\r\n" script += ")\r\n" script += 'for /f "usebackq tokens=*" %%p in ("%~dp0' + reg_name + '") do (\r\n' - script += ' wmic process where "ProcessId=%%p" get CommandLine /value 2>nul | find /i "concore" >nul\r\n' + script += ' powershell -NoProfile -Command "(Get-CimInstance Win32_Process -Filter \'ProcessId=%%p\').CommandLine" 2>nul | findstr /i "concore" >nul\r\n' script += " if not errorlevel 1 (\r\n" script += " echo Killing concore process %%p\r\n" script += " taskkill /F /PID %%p >nul 2>&1\r\n" diff --git a/tests/test_concore.py b/tests/test_concore.py index 033a347..c3096a6 100644 --- a/tests/test_concore.py +++ b/tests/test_concore.py @@ -716,10 +716,37 @@ def test_write_kill_script_generates_bat_file(self): with open(_KILL_SCRIPT_FILE) as f: content = f.read() assert os.path.basename(_PID_REGISTRY_FILE) in content - assert "wmic" in content + assert "wmic" not in content + assert "Get-CimInstance" in content assert "taskkill" in content assert "concore" in content.lower() + @pytest.mark.skipif(sys.platform != "win32", reason="Windows only") + def test_kill_script_kills_concore_process(self): + import subprocess + from concore import _write_kill_script, _KILL_SCRIPT_FILE, _PID_REGISTRY_FILE + + proc = subprocess.Popen( + [sys.executable, "-c", "import time; time.sleep(60)", "concore_node"] + ) + try: + with open(_PID_REGISTRY_FILE, "w") as f: + f.write(str(proc.pid) + "\n") + _write_kill_script() + result = subprocess.run( + ["cmd", "/c", _KILL_SCRIPT_FILE], + capture_output=True, + text=True, + timeout=60, + ) + assert "Killing concore process " + str(proc.pid) in result.stdout + proc.wait(timeout=10) + assert not os.path.exists(_PID_REGISTRY_FILE) + assert not os.path.exists(_KILL_SCRIPT_FILE) + finally: + if proc.poll() is None: + proc.kill() + def test_multi_node_registration(self): from concore import _register_pid, _PID_REGISTRY_FILE