Skip to content

Commit 672216d

Browse files
authored
fix(ssh): let cold remote servers finish starting (pingdotgg#6168)
1 parent 7547280 commit 672216d

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎packages/ssh/src/tunnel.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ const makeSuccessfulProcess = (stdout: string) => {
4545
});
4646
};
4747

48+
const makeDelayedSuccessfulProcess = (stdout: string, delayMs: number) => {
49+
const process = makeSuccessfulProcess(stdout);
50+
return {
51+
...process,
52+
exitCode: Effect.sleep(Duration.millis(delayMs)).pipe(
53+
Effect.as(ChildProcessSpawner.ExitCode(0)),
54+
),
55+
};
56+
};
57+
4858
const makeRunningProcess = (onKill: () => void) => {
4959
let finish: ((exitCode: ChildProcessSpawner.ExitCode) => void) | null = null;
5060
return ChildProcessSpawner.makeHandle({
@@ -174,6 +184,7 @@ describe("ssh tunnel scripts", () => {
174184
assert.include(buildRemoteLaunchScript(), '--base-dir "$DEFAULT_SERVER_HOME"');
175185
assert.notInclude(buildRemoteLaunchScript(), "server-home");
176186
assert.include(buildRemoteLaunchScript(), "Remote T3 server did not become ready");
187+
assert.include(buildRemoteLaunchScript(), 'wait_ready "60000"');
177188
assert.include(buildRemoteLaunchScript({ packageSpec: "t3@nightly" }), "t3@nightly");
178189
assert.include(
179190
buildRemotePairingScript(target),
@@ -235,6 +246,29 @@ describe("ssh tunnel scripts", () => {
235246
}).pipe(Effect.provide(processLayer));
236247
});
237248

249+
it.effect("allows cold remote launches to exceed the default SSH command timeout", () => {
250+
const target = {
251+
alias: "devbox",
252+
hostname: "devbox.example.com",
253+
username: "julius",
254+
port: 2222,
255+
} as const;
256+
const spawner = ChildProcessSpawner.make(() =>
257+
Effect.succeed(makeDelayedSuccessfulProcess('{"remotePort":3774}\n', 75_000)),
258+
);
259+
const spawnerLayer = Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, spawner);
260+
const processLayer = Layer.mergeAll(NodeServices.layer, spawnerLayer, TestClock.layer());
261+
262+
return Effect.gen(function* () {
263+
const fiber = yield* Effect.forkChild(launchOrReuseRemoteServer(target));
264+
yield* Effect.yieldNow;
265+
yield* TestClock.adjust(Duration.seconds(75));
266+
267+
const result = yield* Fiber.join(fiber);
268+
assert.equal(result.remotePort, 3774);
269+
}).pipe(Effect.provide(processLayer));
270+
});
271+
238272
it("allows the remote port picker to run without a state file path", () => {
239273
assert.include(REMOTE_PICK_PORT_SCRIPT, 'const filePath = process.argv[2] ?? "";');
240274
});

‎packages/ssh/src/tunnel.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ const REMOTE_PORT_SCAN_WINDOW = 200;
5454
const SSH_READY_TIMEOUT_MS = 20_000;
5555
const SSH_READY_PROBE_TIMEOUT_MS = 1_000;
5656
const TUNNEL_SHUTDOWN_TIMEOUT_MS = 2_000;
57-
const REMOTE_READY_TIMEOUT_MS = 15_000;
57+
const REMOTE_READY_TIMEOUT_MS = 60_000;
58+
const REMOTE_LAUNCH_TIMEOUT_MS = 90_000;
5859
const REMOTE_REUSE_READY_TIMEOUT_MS = 2_000;
5960

6061
export interface RemoteT3RunnerOptions {
@@ -705,6 +706,7 @@ export const launchOrReuseRemoteServer = Effect.fn("ssh/tunnel.launchOrReuseRemo
705706
const result = yield* runSshCommand(target, {
706707
remoteCommandArgs: ["sh", "-s", "--", remoteStateKey(target)],
707708
stdin: buildRemoteLaunchScript(runner),
709+
timeoutMs: REMOTE_LAUNCH_TIMEOUT_MS,
708710
...(input?.authSecret === undefined ? {} : { authSecret: input.authSecret }),
709711
...(input?.batchMode === undefined ? {} : { batchMode: input.batchMode }),
710712
...(input?.interactiveAuth === undefined ? {} : { interactiveAuth: input.interactiveAuth }),

0 commit comments

Comments
 (0)