From 952072a265ccf0d9f854ab520ec45f72c1573d3f Mon Sep 17 00:00:00 2001 From: Natalie Date: Mon, 8 Jun 2026 09:03:36 -0700 Subject: [PATCH] =?UTF-8?q?fix(transmission):=20=F0=9F=90=9B=20optimize=20?= =?UTF-8?q?ssh=20connection=20warmup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- src/transmission/client.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/transmission/client.ts b/src/transmission/client.ts index ad252a4..bbd3791 100644 --- a/src/transmission/client.ts +++ b/src/transmission/client.ts @@ -4,14 +4,27 @@ import { spawnSync } from "node:child_process"; -// Host + transmission RPC endpoint are configurable; defaults preserve the -// original hardcoded topology so nothing breaks when the env is unset. -const BLACK_HOST = process.env["BLACK_SSH_HOST"] ?? "lilith@10.9.0.4"; +// Host + transmission RPC endpoint are configurable. Default to black's LAN +// address (10.0.0.11): the mesh/overlay (10.9.0.4) needs a ~5s handshake per +// connection and flaps, so a fresh-cold poll there routinely blew past the +// timeout. Override BLACK_SSH_HOST when off-LAN (the whole media stack is anyway). +const BLACK_HOST = process.env["BLACK_SSH_HOST"] ?? "lilith@10.0.0.11"; const RPC_ENDPOINT = process.env["TRANSMISSION_RPC"] ?? "localhost:9091"; const TR = `transmission-remote ${RPC_ENDPOINT}`; +// Reuse one SSH connection across the 3s transfer polls (and add/remove). Without +// it every call paid a full cold handshake — fatal when black is I/O-loaded and +// each connect raced the timeout. Warm, torrent-get drops from ~25s to ~1.5s. +const SSH_OPTS = [ + "-o", "ConnectTimeout=8", + "-o", "BatchMode=yes", + "-o", "ControlMaster=auto", + "-o", "ControlPath=/tmp/tva-cm-%r@%h:%p", + "-o", "ControlPersist=120", +]; + function ssh(cmd: string): { ok: boolean; out: string } { - const r = spawnSync("ssh", [BLACK_HOST, cmd], { encoding: "utf8", timeout: 30_000 }); + const r = spawnSync("ssh", [...SSH_OPTS, BLACK_HOST, cmd], { encoding: "utf8", timeout: 45_000 }); const out = ((r.stdout ?? "") + (r.stderr ?? "")).trim(); return { ok: r.status === 0, out }; }