Repository navigation
fix(ssh): a host whose ssh_config forwards a port can still open its server tunnel (STA-10471) - #28396
Conversation
…server tunnel (STA-10471)
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
0cd43f41-9846-4488-a845-20e12a56ef85
📒 Files selected for processing: 5
src/main/ssh/system-ssh-dynamic-forward-process.test.tssrc/main/ssh/system-ssh-dynamic-forward-process.tssrc/main/ssh/system-ssh-forward-process.test.tssrc/main/ssh/system-ssh-forward-process.tssrc/main/ssh/system-ssh-port-forward-provider.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| // Why `no`: an ssh_config forward the main connection already holds would end this one; the | ||
| // listener probe below is what proves our own -D bound. | ||
| const dynamicArgs = ['-N', '-o', 'ExitOnForwardFailure=no', '-D', `127.0.0.1:${localPort}`] |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '1,240p' src/main/ssh/system-ssh-dynamic-forward-process.ts
sed -n '1,220p' src/main/ssh/system-ssh-dynamic-forward-process.test.tsRepository: stablyai/orca
Length of output: 10009
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- callers and related symbols ---'
rg -n -F --glob '!node_modules' --glob '!dist' -e 'startSystemSshDynamicForwardProcess' -e 'localPort' -e 'dynamicForward' -e 'SOCKS' -e 'socks' src/main src/shared tests 2>/dev/null || true
printf '%s\n' '--- relevant file list ---'
rg --files src/main/ssh src/main | rg '(dynamic|forward|browser|proxy|tunnel|ssh).*\.(ts|tsx)$' | head -120
printf '%s\n' '--- base-to-head diff for the target area ---'
git diff --unified=80 c5d7628686c19d23d50296595061af0962fa3c3d d22938b54fd0f3644765b8759301b5f69ce735f2 -- src/main/ssh/system-ssh-dynamic-forward-process.ts src/main/ssh/system-ssh-dynamic-forward-process.test.ts
printf '%s\n' '--- direct caller source context ---'
rg -l -F --glob '*.ts' --glob '*.tsx' 'startSystemSshDynamicForwardProcess' src | while read -r f; do
echo "FILE: $f"
sed -n '1,280p' "$f"
doneRepository: stablyai/orca
Length of output: 41872
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- SOCKS client and exact route block ---'
nl -ba src/main/browser/system-ssh-socks-client-socket.ts
nl -ba src/main/browser/ssh-browser-network-execution-route.ts | sed -n '185,245p'
printf '%s\n' '--- SSH argument builder and forward process contract ---'
nl -ba src/main/ssh/ssh-system-fallback.ts | sed -n '1,260p'
nl -ba src/main/ssh/system-ssh-forward-process.ts | sed -n '1,240p'
printf '%s\n' '--- all focused tests and references ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'ExitOnForwardFailure' -e 'system SSH dynamic forward' -e 'SystemSshSocksClientSocket' -e 'startDynamicForward' -e 'startSystemSshDynamicForwardProcess' src tests || trueRepository: stablyai/orca
Length of output: 22700
🌐 Web query:
OpenSSH ssh_config ExitOnForwardFailure=no dynamic forwarding behavior when local SOCKS bind fails official manual
💡 Result:
With `ExitOnForwardFailure=no`—the default—`ssh` **does not terminate the connection** if it can’t set up a requested dynamic forward, such as when the local SOCKS listening port cannot be bound. The manual says this option controls whether failure to set up dynamic, local, remote, or tunnel forwards terminates `ssh`; `no` disables that behavior. ([github.com](https://github.com/openssh/openssh-portable/blob/master/ssh_config.5?utm_source=openai))
That means the SSH connection may remain up **without the SOCKS listener being available**. This setting does not govern later failures to connect to a destination through an established forward. ([github.com](https://github.com/openssh/openssh-portable/blob/master/ssh_config.5?utm_source=openai))
Citations:
- 1: https://github.com/openssh/openssh-portable/blob/master/ssh_config.5?utm_source=openai
- 2: https://github.com/openssh/openssh-portable/blob/master/ssh_config.5?utm_source=openai
Validate the SOCKS protocol during startup.
When another process claims the allocated port before SSH binds it, ExitOnForwardFailure=no allows SSH to remain running without its -D listener. waitForDynamicForward treats any successful TCP connection as success, so the browser route can return a tunnel backed by the unrelated listener. The first SystemSshSocksClientSocket then fails its SOCKS handshake instead of using SSH.
Suggested fix
const closeProbe = (): void => {
if (probeSocket === socket) {
probeSocket = undefined
}
socket.removeAllListeners()
socket.destroy()
}
- socket.once('connect', () => {
- closeProbe()
- finish(resolve)
- })
- socket.once('error', () => {
+ const retry = (): void => {
closeProbe()
if (!settled) {
probeTimer = setTimeout(probe, PROBE_INTERVAL_MS)
}
- })
+ }
+ let response = Buffer.alloc(0)
+ socket.once('connect', () => socket.write(new Uint8Array([5, 1, 0])))
+ socket.on('data', (bytes: Buffer) => {
+ response = Buffer.concat([response, bytes])
+ if (response.byteLength < 2) {
+ return
+ }
+ if (response[0] !== 5 || response[1] !== 0) {
+ retry()
+ return
+ }
+ closeProbe()
+ finish(resolve)
+ })
+ socket.once('timeout', retry)
+ socket.once('error', retry)
+ socket.setTimeout(PROBE_INTERVAL_MS)
}…server tunnel (STA-10471) (stablyai#28396) Co-authored-by: m4air <[email protected]> (cherry picked from commit 64dd8f5)
ELI5
Some SSH hosts set up their own port forwards in
~/.ssh/config(aLocalForwardline). When such a host is reached through a jump host or proxy, Orca opens a secondsshprocess for its server tunnel. That second process read the same config line, tried to open the same port a second time, failed, and quit — taking Orca's own tunnel down with it. Now the second process ignores that failure and only gives up when its own port fails.What Changed
Before: a host whose
~/.ssh/configentry hasLocalForward(orRemoteForward) andProxyCommand/ProxyJumpcan't connect after the upgrade. The user sees "Could not connect to the remote Orca runtime" and no projects.After: the host connects. The config's own forward stays owned by Orca's main connection, as before.
Mechanism:
ssh -N -Ltunnel process ran withExitOnForwardFailure=yes. That made ssh exit when any forward failed, including the duplicate config forward the main connection already holds. It now runs withExitOnForwardFailure=no.cannot listen to port: <our port>and stops the process when it appears, during startup or later. The startup error now names that line instead of the last stderr line.ssh -N -Dprocess gets the same flag change. Its startup already waits until its own listener answers.Why
Alternatives considered:
ClearAllForwardings=yes: also clears the-Lgiven on the command line. Checked withssh -G: the command-linelocalforwarddisappears.-Fconfig: would have to re-createInclude,Match, and every proxy setting, and would drift from what OpenSSH resolves.ssh -O forwardthrough a ControlMaster: Windows OpenSSH has no multiplexing, and config-backed hosts often run without Orca's master.Turning off exit-on-any-failure and checking our own port is the only option that works on every platform and for every config.
Linked Issue
STA-10471
Visual Proof
N/A — no UI change; the change is in which ssh process stays up.
Testing
LocalForward 127.0.0.1:47101, and a mainssh -Nconnection holds it:cannot listen to port: 47101/Could not request local forwarding.startSystemSshPortForwardProcess: startup ok, our port 47110 listens, and the process is still alive after 5 s.cannot listen to port: <ours>. That is the line the new watcher matches.-Land-D.pnpm tc:node, oxlint,pnpm run check:code-quality:changed,pnpm lintReview
Agent skill upstream boundary
Notes
channels.c, so the same text comes from Windows OpenSSH.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)