Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Call a VPS host unreachable only on Docker's own SSH connect error

AdityaUmale31158c9f41f3
diff --git a/server/vps-command.ts b/server/vps-command.ts
index fbbadd8bb7..019420533d 100644
--- a/server/vps-command.ts
+++ b/server/vps-command.ts
@@ -26,6 +26,9 @@ export class VpsHostUnreachableError extends Error {}
// OpenSSH's own words when it never reached the host. Exit status 255 alone is not proof: ssh also passes on a remote command's 255.
const SSH_TRANSPORT_FAILURE = /\bssh: (?:Could not resolve hostname|connect to host \S+ port \d+:)/i;
+// Docker reports its own SSH transport failing on one "error during connect" line that quotes ssh's words after "stderr=".
+// The container command shares that stderr, so ssh's words anywhere else are the command's own output.
+const DOCKER_SSH_TRANSPORT_FAILURE = /^error during connect: .*\bstderr=ssh: (?:Could not resolve hostname|connect to host \S+ port \d+:)/im;
/** Only a lookup or connection failure ssh reports itself, or a timeout, means nothing on the host answered. */
function sshNeverReachedHost(error: unknown): boolean {
@@ -121,7 +124,7 @@ export async function defaultRunner(args: string[], options: VpsCommandOptions =
if (code === 0) return resolve({ stdout: stdout.text(), stderr: stderr.text() });
const captured = stderr.text().trim();
const message = captured.slice(-1000) || `Docker-over-SSH exited ${code ?? signal ?? "without a status"}`;
- const error = SSH_TRANSPORT_FAILURE.test(captured) ? new VpsHostUnreachableError(message) : new Error(message);
+ const error = DOCKER_SSH_TRANSPORT_FAILURE.test(captured) ? new VpsHostUnreachableError(message) : new Error(message);
reject(Object.assign(error, { exitCode: code, stdout: stdout.text(), stderr: stderr.text() }));
});
});
diff --git a/server/vps-computer.runner.test.ts b/server/vps-computer.runner.test.ts
index 0af290e105..7a95ea9330 100644
--- a/server/vps-computer.runner.test.ts
+++ b/server/vps-computer.runner.test.ts
@@ -63,6 +63,17 @@ describe("default VPS command runner", () => {
expect(error).not.toBeInstanceOf(VpsHostUnreachableError);
});
+ it("keeps a command's own ssh-looking error output as its failure, not an unreachable host", async () => {
+ const child = fakeChild();
+ const failed = defaultRunner(["exec", "desktop", "sh", "-lc", "ssh example"]);
+ child.stdout.write("tried");
+ child.stderr.write("ssh: connect to host example port 22: Connection refused\n");
+ child.emit("close", 2, null);
+ const error = await failed.catch((failure: unknown) => failure);
+ expect(error).not.toBeInstanceOf(VpsHostUnreachableError);
+ expect(error).toMatchObject({ exitCode: 2, stdout: "tried", stderr: "ssh: connect to host example port 22: Connection refused\n" });
+ });
+
it("keeps a failed command's exit status and output on the error", async () => {
const child = fakeChild();
const failed = defaultRunner(["exec", "desktop", "false"]);