惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园_首页
U
Unit 42
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
MongoDB | Blog
MongoDB | Blog
美团技术团队
H
Help Net Security
G
Google Developers Blog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
M
MIT News - Artificial intelligence
腾讯CDC
IT之家
IT之家
Vercel News
Vercel News
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
Last Week in AI
Last Week in AI
I
InfoQ
博客园 - 司徒正美
A
About on SuperTechFans

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(rpc): kill measurement gateway trees on windows · ope...
vincentkoc · 2026-06-20 · via Recent Commits to openclaw:main
11

// Measures gateway RPC round-trip time by launching an isolated local gateway

22

// and writing qa-lab-compatible summary artifacts.

3-

import { spawn } from "node:child_process";

3+

import { spawn, spawnSync } from "node:child_process";

44

import { randomUUID } from "node:crypto";

55

import { existsSync } from "node:fs";

66

import fs from "node:fs/promises";

@@ -264,6 +264,10 @@ function defaultKillProcess(pid, signal) {

264264

return process.kill(pid, signal);

265265

}

266266267+

function defaultRunTaskkill(command, args, options) {

268+

return spawnSync(command, args, options);

269+

}

270+267271

async function defaultOpen(filePath, flags) {

268272

return await fs.open(filePath, flags);

269273

}

@@ -277,10 +281,15 @@ function resolveOpenClawLaunchArgs(repoRoot, sourceEntryExists = existsSync) {

277281

}

278282279283

/**

280-

* Signals the gateway process group on POSIX so spawned children are cleaned up.

284+

* Signals the gateway process tree so spawned package-manager children are cleaned up.

281285

*/

282-

export function signalGatewayProcess(child, signal, killProcess = defaultKillProcess) {

283-

if (process.platform !== "win32" && typeof child.pid === "number") {

286+

export function signalGatewayProcess(

287+

child,

288+

signal,

289+

killProcess = defaultKillProcess,

290+

{ platform = process.platform, runTaskkill = defaultRunTaskkill } = {},

291+

) {

292+

if (platform !== "win32" && typeof child.pid === "number") {

284293

try {

285294

killProcess(-child.pid, signal);

286295

return true;

@@ -291,6 +300,16 @@ export function signalGatewayProcess(child, signal, killProcess = defaultKillPro

291300

throw error;

292301

}

293302

}

303+

if (platform === "win32" && typeof child.pid === "number") {

304+

const args = ["/PID", String(child.pid), "/T"];

305+

if (signal === "SIGKILL") {

306+

args.push("/F");

307+

}

308+

const result = runTaskkill("taskkill", args, { stdio: "ignore" });

309+

if (!result?.error && result?.status === 0) {

310+

return true;

311+

}

312+

}

294313

try {

295314

return child.kill(signal);

296315

} catch (error) {

@@ -304,8 +323,12 @@ export function signalGatewayProcess(child, signal, killProcess = defaultKillPro

304323

/**

305324

* Checks process-group liveness without treating an already-exited child as an error.

306325

*/

307-

export function isGatewayProcessAlive(child, killProcess = defaultKillProcess) {

308-

if (process.platform !== "win32" && typeof child.pid === "number") {

326+

export function isGatewayProcessAlive(

327+

child,

328+

killProcess = defaultKillProcess,

329+

{ platform = process.platform } = {},

330+

) {

331+

if (platform !== "win32" && typeof child.pid === "number") {

309332

try {

310333

killProcess(-child.pid, 0);

311334

return true;

@@ -319,17 +342,17 @@ export function isGatewayProcessAlive(child, killProcess = defaultKillProcess) {

319342

return child.exitCode === null && child.signalCode === null;

320343

}

321344322-

function signalGatewayProcessForParentExit(child, signal, killProcess) {

345+

function signalGatewayProcessForParentExit(child, signal, killProcess, signalOptions) {

323346

try {

324-

signalGatewayProcess(child, signal, killProcess);

347+

signalGatewayProcess(child, signal, killProcess, signalOptions);

325348

} catch {

326349

// Parent shutdown cleanup is best effort; the original signal should win.

327350

}

328351

}

329352330-

function gatewayProcessAliveForParentExit(child, killProcess) {

353+

function gatewayProcessAliveForParentExit(child, killProcess, signalOptions) {

331354

try {

332-

return isGatewayProcessAlive(child, killProcess);

355+

return isGatewayProcessAlive(child, killProcess, signalOptions);

333356

} catch {

334357

return true;

335358

}

@@ -340,28 +363,37 @@ function gatewayProcessAliveForParentExit(child, killProcess) {

340363

*/

341364

export function installGatewayParentCleanup(

342365

child,

343-

{ killProcess = defaultKillProcess, processLike = process } = {},

366+

{

367+

killProcess = defaultKillProcess,

368+

platform = process.platform,

369+

processLike = process,

370+

runTaskkill = defaultRunTaskkill,

371+

} = {},

344372

) {

373+

const signalOptions = { platform, runTaskkill };

345374

const signalHandlers = new Map();

346375

let forceKillTimer;

347376

let parentSignalPending = false;

348377

const forceCleanup = (signal) => {

349-

signalGatewayProcessForParentExit(child, signal, killProcess);

350-

if (process.platform !== "win32") {

351-

signalGatewayProcessForParentExit(child, "SIGKILL", killProcess);

378+

signalGatewayProcessForParentExit(child, signal, killProcess, signalOptions);

379+

if (platform !== "win32") {

380+

signalGatewayProcessForParentExit(child, "SIGKILL", killProcess, signalOptions);

352381

}

353382

};

354383

const cleanupAndReraise = (signal) => {

355384

parentSignalPending = true;

356-

signalGatewayProcessForParentExit(child, signal, killProcess);

385+

signalGatewayProcessForParentExit(child, signal, killProcess, signalOptions);

357386

const finish = () => {

358387

forceKillTimer = undefined;

359-

signalGatewayProcessForParentExit(child, "SIGKILL", killProcess);

388+

signalGatewayProcessForParentExit(child, "SIGKILL", killProcess, signalOptions);

360389

processLike.kill?.(processLike.pid, signal);

361390

};

362391

// Signal handlers can give the detached gateway group one normal teardown

363392

// grace window before re-raising; process exit cleanup cannot wait.

364-

if (process.platform === "win32" || !gatewayProcessAliveForParentExit(child, killProcess)) {

393+

if (

394+

platform === "win32" ||

395+

!gatewayProcessAliveForParentExit(child, killProcess, signalOptions)

396+

) {

365397

processLike.kill?.(processLike.pid, signal);

366398

return;

367399

}

@@ -393,31 +425,40 @@ export function installGatewayParentCleanup(

393425

return removeHandlers;

394426

}

395427396-

async function waitForGatewayExit(child, timeoutMs, killProcess = defaultKillProcess) {

428+

async function waitForGatewayExit(

429+

child,

430+

timeoutMs,

431+

killProcess = defaultKillProcess,

432+

signalOptions = {},

433+

) {

397434

const deadline = Date.now() + timeoutMs;

398435

while (Date.now() <= deadline) {

399-

if (!isGatewayProcessAlive(child, killProcess)) {

436+

if (!isGatewayProcessAlive(child, killProcess, signalOptions)) {

400437

return true;

401438

}

402439

await sleep(Math.min(25, Math.max(0, deadline - Date.now())));

403440

}

404-

return !isGatewayProcessAlive(child, killProcess);

441+

return !isGatewayProcessAlive(child, killProcess, signalOptions);

405442

}

406443407444

/**

408445

* Stops the gateway with SIGTERM first and SIGKILL after the grace window.

409446

*/

410447

export async function stopGateway(child, options = {}) {

411-

if (!isGatewayProcessAlive(child, options.killProcess)) {

448+

const signalOptions = {

449+

platform: options.platform ?? process.platform,

450+

runTaskkill: options.runTaskkill ?? defaultRunTaskkill,

451+

};

452+

if (!isGatewayProcessAlive(child, options.killProcess, signalOptions)) {

412453

return;

413454

}

414455

const killGraceMs = Math.max(0, options.killGraceMs ?? 1_500);

415456

const forceKillGraceMs = Math.max(0, options.forceKillGraceMs ?? GATEWAY_FORCE_KILL_GRACE_MS);

416-

signalGatewayProcess(child, "SIGTERM", options.killProcess);

417-

const exited = await waitForGatewayExit(child, killGraceMs, options.killProcess);

457+

signalGatewayProcess(child, "SIGTERM", options.killProcess, signalOptions);

458+

const exited = await waitForGatewayExit(child, killGraceMs, options.killProcess, signalOptions);

418459

if (!exited) {

419-

signalGatewayProcess(child, "SIGKILL", options.killProcess);

420-

await waitForGatewayExit(child, forceKillGraceMs, options.killProcess);

460+

signalGatewayProcess(child, "SIGKILL", options.killProcess, signalOptions);

461+

await waitForGatewayExit(child, forceKillGraceMs, options.killProcess, signalOptions);

421462

}

422463

}

423464