Skip to content

Commit 533f1ef

Browse files
committed
fix(infra): gateway pid probe no longer hangs when ps sampling stalls
readGatewayProcessArgsSync probes ps to verify gateway argv before signaling or reporting listener PIDs. The darwin branch already passed timeout: 1000, but spawnSync defaults killSignal to SIGTERM, which an unresponsive or hung ps child can ignore and keep the gateway process blocked past the timeout. Force killSignal: SIGKILL (matching the doctor probe fix in #109243) so a stalled ps probe is reaped at the deadline instead of hanging gateway signal verification and listener PID discovery. Extract GATEWAY_PS_PROBE_TIMEOUT_MS for the named timeout and assert the full spawnSync options (encoding / killSignal / timeout) in the darwin test.
1 parent c46cc1e commit 533f1ef

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎src/infra/gateway-processes.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ describe("gateway-processes", () => {
117117
"run",
118118
]);
119119
expect(readGatewayProcessArgsSync(124)).toBeNull();
120+
expect(spawnSyncMock).toHaveBeenCalledWith("ps", ["-o", "command=", "-p", "123"], {
121+
encoding: "utf8",
122+
killSignal: "SIGKILL",
123+
timeout: 1_000,
124+
});
120125
});
121126

122127
it("falls back from powershell to wmic for windows process args", () => {

‎src/infra/gateway-processes.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import {
1111

1212
// Gateway process helpers verify argv before signaling or reporting listener
1313
// PIDs so stale port owners cannot be mistaken for OpenClaw.
14+
// A stalled ps probe must not block the gateway process indefinitely. spawnSync
15+
// defaults to SIGTERM, which an unresponsive process can ignore, so we force
16+
// SIGKILL once the timeout elapses.
17+
const GATEWAY_PS_PROBE_TIMEOUT_MS = 1_000;
18+
1419
/** Read command argv for a PID using the current platform's process APIs. */
1520
export function readGatewayProcessArgsSync(pid: number): string[] | null {
1621
if (process.platform === "linux") {
@@ -23,7 +28,8 @@ export function readGatewayProcessArgsSync(pid: number): string[] | null {
2328
if (process.platform === "darwin") {
2429
const ps = spawnSync("ps", ["-o", "command=", "-p", String(pid)], {
2530
encoding: "utf8",
26-
timeout: 1000,
31+
killSignal: "SIGKILL",
32+
timeout: GATEWAY_PS_PROBE_TIMEOUT_MS,
2733
});
2834
if (ps.error || ps.status !== 0) {
2935
return null;

0 commit comments

Comments
 (0)