Skip to content

Commit 23f56dc

Browse files
kcazinclaude
andcommitted
fix(server): SSH device-host tunnels no longer inherit ControlMaster
The device-host tunnel inherited ControlMaster/ControlPersist from the user's ssh config, so it became a mux client that handed its forwards to the control master and exited. The reconnect loop then leaked two listening ports into the master every ~1.5 s until the ephemeral range ran out. Opt the tunnel out of multiplexing, as the environment tunnel already does (#4347). Fixes #17437 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 8d199b4 commit 23f56dc

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎apps/server/src/device/SshDeviceHost.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ it.effect("preserves installed status after probes and cleans failed agent activ
2020
const home = yield* fs.makeTempDirectoryScoped();
2121
const modes: string[] = [];
2222
const owners: string[] = [];
23+
const tunnelArgs: string[][] = [];
24+
const commandArgs: string[][] = [];
2325
let forwards = 0;
2426
let failForward = true;
2527
let rejectConfig = true;
2628
const spawner = ChildProcessSpawner.make((command) =>
2729
Effect.gen(function* () {
2830
if (command._tag !== "StandardCommand") return yield* Effect.die("Unexpected command");
2931
const forwarding = command.args.includes("-N");
32+
(forwarding ? tunnelArgs : commandArgs).push([...command.args]);
3033
let output = "";
3134
if (forwarding) {
3235
if (failForward) {
@@ -132,6 +135,19 @@ it.effect("preserves installed status after probes and cleans failed agent activ
132135
expect((yield* host.summary).agentDeviceInstalled).toBe(true);
133136
yield* host.stopAgent;
134137
expect(forwards).toBe(1);
138+
const multiplexingOff = ["ControlMaster=no", "ControlPath=none", "ControlPersist=no"];
139+
expect(tunnelArgs.length).toBeGreaterThan(0);
140+
for (const args of tunnelArgs) {
141+
for (const option of multiplexingOff) {
142+
const index = args.indexOf(option);
143+
expect(index).toBeGreaterThan(0);
144+
expect(args[index - 1]).toBe("-o");
145+
}
146+
}
147+
expect(commandArgs.length).toBeGreaterThan(0);
148+
for (const args of commandArgs) {
149+
for (const option of multiplexingOff) expect(args).not.toContain(option);
150+
}
135151
yield* host.stop;
136152
expect(forwards).toBe(0);
137153
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),

‎apps/server/src/device/SshDeviceHost.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ export const make = Effect.fn("SshDeviceHost.make")(function* (
242242
...identityArgs(config),
243243
"-o",
244244
"ExitOnForwardFailure=yes",
245+
// A multiplexed client hands its -L forwards to the control master and exits,
246+
// so the tunnel must own its own connection.
247+
"-o",
248+
"ControlMaster=no",
249+
"-o",
250+
"ControlPath=none",
251+
"-o",
252+
"ControlPersist=no",
245253
"-o",
246254
"ServerAliveInterval=10",
247255
"-o",

0 commit comments

Comments
 (0)