# Files changed · PR \#7815 · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/pull/7815/diffs)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

[fix\(desktop\): give the SSH readiness probe room for high-RTT links](https://git.cafe/pingdotgg/t3code/pull/7815.md)

Version: 7

Head commit: 82a6cf33e74087b61bb5f922bb15eec8985727a6

Base commit: 6cf704beb5c9fb77603ca846fef18ca96ab3d669

Comparison base: 6cf704beb5c9fb77603ca846fef18ca96ab3d669

Showing up to 20 entries from this revision. If the pull request changes, reopen the first page before continuing.

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

Status: modified; +74; −2

```diff
@@ -155,7 +155,8 @@
     assert.include(launch, "T3_ARCHIVE_MODE=1");
     assert.include(launch, "T3_RELEASE_BASE_URL='https://mirror.example/t3'");
     assert.include(launch, '"$RUNNER_FILE" __ssh-helper pick-port "$PORT_FILE"');
+    assert.include(launch, '"$RUNNER_FILE" __ssh-helper wait-ready "$REMOTE_PORT" "$1" "1000"');
+    assert.include(launch, 'node - "$REMOTE_PORT" "$1" "1000"');
-    assert.include(launch, '"$RUNNER_FILE" __ssh-helper wait-ready "$REMOTE_PORT"');
     assert.include(launch, '"$RUNNER_FILE" __ssh-helper runtime-port "$DEFAULT_RUNTIME_FILE"');
     assert.include(SshTunnel.buildRemoteLaunchScript(NODE_SCRIPT), "T3_ARCHIVE_MODE=0");
   });
@@ -420,6 +421,77 @@
     ),
   );
 
+  it.effect.each(["initial connection", "reuse"] as const)(
+    "accepts a slow healthy HTTP response on tunnel %s",
+    (phase) =>
+      Effect.gen(function* () {
+        const probeStarted = yield* Deferred.make<void>();
+        const respond = yield* Deferred.make<void>();
+        let slow = phase === "initial connection";
+        let interruptedProbes = 0;
+        let forwards = 0;
+        let kills = 0;
+        let stops = 0;
+        const spawner = ChildProcessSpawner.make((command) =>
+          Effect.sync(() => {
+            const args = commandArgs(command);
+            if (args.includes("-N")) {
+              forwards += 1;
+              return makeRunningProcess(() => {
+                kills += 1;
+              });
+            }
+            if (args.some((arg, index) => arg === "-s" && args[index + 1] === "--")) {
+              return makeSuccessfulProcess('{"remotePort":3773}\n');
+            }
+            if (args.includes("sh")) stops += 1;
+            return makeSuccessfulProcess("");
+          }),
+        );
+        const httpClient = HttpClient.make((request) =>
+          Effect.gen(function* () {
+            if (slow) {
+              yield* Deferred.succeed(probeStarted, undefined);
+              yield* Deferred.await(respond).pipe(
+                Effect.onInterrupt(() =>
+                  Effect.sync(() => {
+                    interruptedProbes += 1;
+                  }),
+                ),
+              );
+            }
+            return HttpClientResponse.fromWeb(request, new Response("", { status: 200 }));
+          }),
+        );
+        const layer = Layer.mergeAll(
+          NodeServices.layer,
+          Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, spawner),
+          Layer.succeed(HttpClient.HttpClient, httpClient),
+          Layer.succeed(NetService.NetService, testNetService),
+          SshAuth.SshPasswordPrompt.disabledLayer,
+          SshTunnel.SshEnvironmentManager.layer({ resolveCliRunner: Effect.succeed(ARCHIVE) }),
+        );
+        yield* Effect.gen(function* () {
+          const manager = yield* SshTunnel.SshEnvironmentManager;
+          const target = { alias: "devbox", hostname: "devbox", username: null, port: null };
+          if (phase === "reuse") {
+            yield* manager.ensureEnvironment(target);
+            slow = true;
+          }
+          const connection = yield* Effect.forkChild(manager.ensureEnvironment(target));
+          yield* Deferred.await(probeStarted);
+          yield* TestClock.adjust("3 seconds");
+          assert.equal(interruptedProbes, 0, "a slow healthy response must not be canceled");
+          yield* Deferred.succeed(respond, undefined);
+          const result = yield* Fiber.join(connection);
+          assert.equal(result.httpBaseUrl, "http://127.0.0.1:41773/");
+          assert.equal(forwards, 1);
+          assert.equal(kills, 0);
+          assert.equal(stops, 0);
+        }).pipe(Effect.provide(layer), Effect.scoped);
+      }),
+  );
+
   it("preserves primitive readiness reason values in diagnostic output", () => {
     assert.deepEqual(
       SshTunnel.describeReadinessCause({
@@ -535,7 +607,7 @@
         stale = true;
         const reconnect = yield* Effect.forkChild(manager.ensureEnvironment(target));
         yield* Deferred.await(probeStarted);
-        yield* TestClock.adjust("2 seconds");
+        yield* TestClock.adjust("8 seconds");
         yield* Fiber.join(reconnect);
         assert.equal(forwards, 2);
         assert.equal(kills, 1);
```

## packages/ssh/src/tunnel.ts

Status: modified; +9; −1

```diff
@@ -49,7 +49,10 @@
 const DEFAULT_REMOTE_PORT = 3773;
 const REMOTE_PORT_SCAN_WINDOW = 200;
 const SSH_READY_TIMEOUT_MS = 20_000;
+// Remote loopback probes must fit within the shell's 2s reuse window.
 const SSH_READY_PROBE_TIMEOUT_MS = 1_000;
+// Probes through SSH cross the network, both when connecting and reusing a tunnel.
+const SSH_TUNNEL_READY_PROBE_TIMEOUT_MS = 8_000;
 const TUNNEL_SHUTDOWN_TIMEOUT_MS = 2_000;
 const TUNNEL_STDERR_TAIL_CHARS = 16_384;
 const REMOTE_READY_TIMEOUT_MS = 60_000;
@@ -1299,6 +1302,7 @@
     waitForHttpReady({
       baseUrl: input.httpBaseUrl,
       timeoutMs: SSH_READY_TIMEOUT_MS,
+      probeTimeoutMs: SSH_TUNNEL_READY_PROBE_TIMEOUT_MS,
     }),
     exitFailure,
   ).pipe(
@@ -1656,7 +1660,11 @@
         remotePort: entry.remotePort,
       });
       const readinessExit = yield* Effect.exit(
-        waitForHttpReady({ baseUrl: entry.httpBaseUrl, timeoutMs: 2_000 }),
+        waitForHttpReady({
+          baseUrl: entry.httpBaseUrl,
+          timeoutMs: SSH_TUNNEL_READY_PROBE_TIMEOUT_MS,
+          probeTimeoutMs: SSH_TUNNEL_READY_PROBE_TIMEOUT_MS,
+        }),
       );
       if (Exit.isSuccess(readinessExit)) {
         yield* Effect.logDebug("ssh.environment.tunnel.reused", {
```
