The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 18:30 UTC
fix(ssh): timed-out SSH commands no longer leave a proxy helper running (#35775)
Julius Marminge committed
Nov 12, 2026 at 17:45 UTC
12421dadea2db278bad8d804c4cf4cff2059e753
2 files changed
+40
packages/ssh/src/command.test.ts
+39
@@ -149,6 +149,45 @@ describe("ssh command", () => {
149
}).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
150
);
151
152
+ it.live.skipIf(HostProcess.Platform.defaultValue() === "win32")(
153
+ "a timed-out command leaves no helper running that ignored SIGTERM",
154
+ () =>
155
+ Effect.gen(function* () {
156
+ const nativeSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
157
+ // Stands in for ssh and a ProxyCommand: ssh exits on SIGTERM, the proxy ignores it.
158
+ const spawner = ChildProcessSpawner.make((command) =>
159
+ nativeSpawner.spawn(
160
+ ChildProcess.make(
161
+ process.execPath,
162
+ [
163
+ "-e",
164
+ `const proxy = require("node:child_process").spawn("sh", ["-c", "trap '' TERM; exec sleep 60"], { stdio: "ignore" });
165
+ process.stdout.write(proxy.pid + "\\n");
166
+ setInterval(() => {}, 1000);`,
167
+ ],
168
+ command._tag === "StandardCommand" ? command.options : {},
169
+ ),
170
+ ),
171
+ );
172
+ const failure = yield* runSshCommand(
173
+ { alias: "synthetic-fixture", hostname: "synthetic-fixture", username: null, port: null },
174
+ { timeoutMs: 1_000, keepErrorOutputTail: true },
175
+ ).pipe(
176
+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
177
+ Effect.flip,
178
+ );
179
+ assert.instanceOf(failure, SshCommandError);
180
+ assert.equal(failure.message, "SSH command timed out after 1000ms.");
181
+ const proxyPid = Number(failure.stdout?.trim());
182
+ assert.isTrue(Number.isSafeInteger(proxyPid) && proxyPid > 1);
183
+ const state = (yield* nativeSpawner.string(
184
+ ChildProcess.make("ps", ["-p", String(proxyPid), "-o", "stat="]),
185
+ )).trim();
186
+ if (state !== "" && !state.startsWith("Z")) process.kill(proxyPid, "SIGKILL");
187
+ assert.isTrue(state === "" || state.startsWith("Z"), `proxy still running (${state})`);
188
+ }).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
189
+ );
190
+
191
it.live("enables server-alive checks for long remote commands", () =>
192
Effect.gen(function* () {
193
// Ask OpenSSH for its effective configuration without opening a connection.
packages/ssh/src/command.ts
+1
@@ -274,6 +274,7 @@ const runSshCommandInScope = Effect.fn("ssh/command.runSshCommand.inScope")(func
274
ChildProcess.make(sshCommand, args, {
275
env: environment,
276
extendEnv: true,
277
+ forceKillAfter: "1 second",
278
stdin: {
279
stream: stdinStream(input.stdin),
280
endOnDone: true,