Skip to content

The agent that grows with you

fix(desktop): add SSH keepalive to prevent tunnel drop after idle (#74998)

webtecnicaac0cfa7db94c
diff --git a/apps/desktop/electron/ssh-connection.test.ts b/apps/desktop/electron/ssh-connection.test.ts
index 7a88436d751..edaa965dbd7 100644
--- a/apps/desktop/electron/ssh-connection.test.ts
+++ b/apps/desktop/electron/ssh-connection.test.ts
@@ -161,6 +161,9 @@ test('baseSshOptions carries the house ControlMaster/BatchMode/accept-new policy
assert.match(joined, /StrictHostKeyChecking=accept-new/)
assert.match(joined, /ExitOnForwardFailure=yes/)
assert.match(joined, /ConnectTimeout=15/)
+ assert.match(joined, /ServerAliveInterval=15/)
+ assert.match(joined, /ServerAliveCountMax=3/)
+ assert.match(joined, /TCPKeepAlive=yes/)
assert.ok(!joined.includes('StrictHostKeyChecking=no'), 'never disables host-key checking')
})
diff --git a/apps/desktop/electron/ssh-connection.ts b/apps/desktop/electron/ssh-connection.ts
index f1be22c50b1..527d0d6e7b9 100644
--- a/apps/desktop/electron/ssh-connection.ts
+++ b/apps/desktop/electron/ssh-connection.ts
@@ -258,7 +258,15 @@ function baseSshOptions(controlPath, connectTimeoutMs?) {
'-o',
'ExitOnForwardFailure=yes',
'-o',
- `ConnectTimeout=${connectSecs}`
+ `ConnectTimeout=${connectSecs}`,
+ // Keepalive: send a message every 15s, drop after 3 missed replies (45s)
+ // so NAT/firewall timeouts don't silently kill an idle connection.
+ '-o',
+ 'ServerAliveInterval=15',
+ '-o',
+ 'ServerAliveCountMax=3',
+ '-o',
+ 'TCPKeepAlive=yes'
]
}