Commit 0396fc4
j-zhangyiyuan
fix: kill entire CLI process tree on stop/forceStop (Windows)
On Windows, ChildProcess.kill() / Popen.terminate() only terminates the
immediate process via TerminateProcess(), leaving grandchildren (copilot
workers, MCP servers, etc.) orphaned. Each session cycle leaks a full
process tree that accumulates until OOM.
Fix: use \ askkill /T /F /PID\ on Windows to terminate the entire tree.
On Unix, use os.killpg() in Python for process group cleanup.
Node.js (client.ts):
- Add killProcessTree() helper wrapping taskkill /T on Windows
- Replace child.kill() in stop() and forceStop() with killProcessTree()
Python (client.py):
- Add _kill_process_tree() helper with taskkill /T (Windows) and
os.killpg() (Unix) strategies
- Replace self._cli_process.terminate()/kill() in stop() and
force_stop() with _kill_process_tree()
Tested: spawned a 2-level process tree on Windows, confirmed both parent
and child are terminated after taskkill /T.
Closes #18041 parent 949de90 commit 0396fc4
2 files changed
Lines changed: 77 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
155 | 185 | | |
156 | 186 | | |
157 | 187 | | |
| |||
1086 | 1116 | | |
1087 | 1117 | | |
1088 | 1118 | | |
1089 | | - | |
| 1119 | + | |
1090 | 1120 | | |
1091 | 1121 | | |
1092 | 1122 | | |
| |||
1213 | 1243 | | |
1214 | 1244 | | |
1215 | 1245 | | |
1216 | | - | |
| 1246 | + | |
1217 | 1247 | | |
1218 | 1248 | | |
1219 | 1249 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1182 | 1182 | | |
1183 | 1183 | | |
1184 | 1184 | | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
1185 | 1226 | | |
1186 | 1227 | | |
1187 | 1228 | | |
| |||
1892 | 1933 | | |
1893 | 1934 | | |
1894 | 1935 | | |
1895 | | - | |
| 1936 | + | |
1896 | 1937 | | |
1897 | 1938 | | |
1898 | 1939 | | |
1899 | 1940 | | |
1900 | 1941 | | |
1901 | 1942 | | |
1902 | | - | |
| 1943 | + | |
1903 | 1944 | | |
1904 | 1945 | | |
1905 | 1946 | | |
| |||
1958 | 1999 | | |
1959 | 2000 | | |
1960 | 2001 | | |
1961 | | - | |
| 2002 | + | |
1962 | 2003 | | |
1963 | 2004 | | |
1964 | 2005 | | |
| |||
0 commit comments