diff --git a/apps/t3/src/runtimeApiServer.test.ts b/apps/t3/src/runtimeApiServer.test.ts index 3c4bbaf65c..a739ba3bc3 100644 --- a/apps/t3/src/runtimeApiServer.test.ts +++ b/apps/t3/src/runtimeApiServer.test.ts @@ -867,6 +867,46 @@ describe("runtimeApiServer", () => { client.socket.close(); }); + it("force-kills commands that ignore SIGTERM after timeout", async () => { + if (process.platform === "win32") { + return; + } + + const server = await startRuntimeApiServer({ + port: 0, + launchCwd: process.cwd(), + }); + servers.push(server); + + const client = await connectClient(server.wsUrl); + await client.nextMessage(); + + const startedAt = Date.now(); + const response = await sendRequest( + client.socket, + client.nextMessage, + "terminal-timeout-sigkill-1", + "terminal.run", + { + command: "trap '' TERM; while true; do sleep 1; done", + cwd: process.cwd(), + timeoutMs: 100, + }, + ); + const elapsedMs = Date.now() - startedAt; + expect(response.ok).toBe(true); + if (!response.ok) { + throw new Error("Expected SIGTERM-resistant command response to succeed."); + } + const payload = response.result as { + timedOut: boolean; + }; + expect(payload.timedOut).toBe(true); + expect(elapsedMs).toBeLessThan(5_000); + + client.socket.close(); + }); + it("runs terminal commands in the requested cwd", async () => { const server = await startRuntimeApiServer({ port: 0, diff --git a/apps/t3/src/runtimeApiServer.ts b/apps/t3/src/runtimeApiServer.ts index 3b8961f23d..4708218e36 100644 --- a/apps/t3/src/runtimeApiServer.ts +++ b/apps/t3/src/runtimeApiServer.ts @@ -273,7 +273,7 @@ async function runTerminalCommand(parsed: z.infer { - if (!child.killed) { + if (child.exitCode === null && child.signalCode === null) { child.kill("SIGKILL"); } }, 1_000).unref();