Skip to content
TypeScript

fix(ssh): detect lost connections during remote commands (#23025)

Ümit Demir0ce257b8804a
diff --git a/packages/ssh/src/command.test.ts b/packages/ssh/src/command.test.ts
index 0ba12303985..9503e4d0606 100644
--- a/packages/ssh/src/command.test.ts
+++ b/packages/ssh/src/command.test.ts
@@ -143,6 +143,18 @@ describe("ssh command", () => {
}).pipe(Effect.provide(NodeServices.layer)),
);
+ it.live("enables server-alive checks for long remote commands", () =>
+ Effect.gen(function* () {
+ // Ask OpenSSH for its effective configuration without opening a connection.
+ const { stdout } = yield* runSshCommand(
+ { alias: "synthetic-fixture", hostname: "synthetic-fixture", username: null, port: null },
+ { preHostArgs: ["-F", "none", "-G"], timeoutMs: 900_000 },
+ );
+ assert.match(stdout, /^serveraliveinterval 15\r?$/mu);
+ assert.match(stdout, /^serveralivecountmax 3\r?$/mu);
+ }).pipe(Effect.provide(NodeServices.layer)),
+ );
+
it.effect("redacts credentials from stdout in non-zero command failures", () => {
const spawner = ChildProcessSpawner.make(() =>
Effect.succeed(makeFailedProcess({ stdout: '{"credential":"pairing-secret"}\n' })),
diff --git a/packages/ssh/src/command.ts b/packages/ssh/src/command.ts
index dbe1bf7e305..5011eea7cd7 100644
--- a/packages/ssh/src/command.ts
+++ b/packages/ssh/src/command.ts
@@ -202,6 +202,11 @@ const runSshCommandInScope = Effect.fn("ssh/command.runSshCommand.inScope")(func
...baseSshArgs(target, {
batchMode: input.batchMode ?? (input.interactiveAuth ? "no" : "yes"),
}),
+ // Cold installs need a long command budget; a lost connection must fail sooner.
+ "-o",
+ "ServerAliveInterval=15",
+ "-o",
+ "ServerAliveCountMax=3",
...(input.preHostArgs ?? []),
"--",
hostSpec,