Repository navigation
fix(ssh): an SSH host comes back after restarting Orca instead of staying offline (STA-10476) - #28398
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments: 1
src/main/ssh/system-ssh-orphaned-forward.ts: 1
136-145: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueReturn false when the orphan does not exit.
stopOrphanedOrcaSshForwardreturnstrueeven when the orphan survives both waits. It also returnstruewhenkillthrowsEPERM. In both cases the caller retries the bind once and fails withEADDRINUSEanyway. The function comment saystruemeans the orphan was signalled, so this is not a correctness failure. However, the caller's retry depends on that boolean. Use the result ofwaitUntilGoneso thattruemeans the port was actually freed.Proposed fix
try { deps.kill(orphan.pid, 'SIGTERM') - if (!(await waitUntilGone(orphan.pid, deps.kill, TERM_WAIT_MS))) { - deps.kill(orphan.pid, 'SIGKILL') - await waitUntilGone(orphan.pid, deps.kill, KILL_WAIT_MS) - } - } catch { - // Exited between the table read and the signal; the caller's retry decides. + if (await waitUntilGone(orphan.pid, deps.kill, TERM_WAIT_MS)) { + return true + } + deps.kill(orphan.pid, 'SIGKILL') + return await waitUntilGone(orphan.pid, deps.kill, KILL_WAIT_MS) + } catch { + // Exited between the table read and the signal, or the signal was refused. + return isGone(orphan.pid, deps.kill) } - return true }
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
d66f0cbd-1c88-4207-a5be-b61850d87065
📥 Commits
Reviewing files that changed from the base of the PR and between b3ad227 and 72661531f8892fba1bd3b4445cf2629d9ae5c50b.
📒 Files selected for processing: 14
src/main/ipc/ssh-app-shutdown.test.tssrc/main/ipc/ssh-ipc-mock-shapes.tssrc/main/ipc/ssh-ipc-module-mocks.tssrc/main/ipc/ssh-ipc-test-harness.tssrc/main/ipc/ssh-shutdown-drain.tssrc/main/ssh/orcad-managed-tunnel-manager.tssrc/main/ssh/orcad-managed-tunnel.test.tssrc/main/ssh/orcad-managed-tunnel.tssrc/main/ssh/ssh-port-forward.test.tssrc/main/ssh/ssh-port-forward.tssrc/main/ssh/system-ssh-forward-process.test.tssrc/main/ssh/system-ssh-forward-process.tssrc/main/ssh/system-ssh-orphaned-forward.test.tssrc/main/ssh/system-ssh-orphaned-forward.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| this.managerGeneration += 1 | ||
| this.active.clear() | ||
| await this.forwards.closeAll() |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
Prevent managed tunnels from restarting during shutdown.
If a joined build fails as superseded, ensure retries it with the new managerGeneration. That retry can open a forward after closeAll has taken its snapshot. A rebuild waiting on an in-flight build can also call ensure after shutdown. Mark the manager as shutting down and reject new builds, in addition to superseding existing ones.
| @@ -191,6 +191,11 @@ export class SshPortForwardManager { | |||
| await Promise.all(stale.map((id) => this.removeForwardAsync(id))) | |||
| } | |||
|
|
|||
| /** Stops every forward and waits until each released its port; quit uses it. */ | |||
| async closeAll(): Promise<void> { | |||
| await Promise.all([...this.forwards.keys()].map((id) => this.removeForwardAsync(id))) | |||
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
Include pending forward starts in closeAll.
If provider.start is still pending, addForwardWithId has not added that forward to this.forwards. closeAll can finish before the start resolves. The start then registers a live forward after shutdown, so its SSH process can outlive Orca. Track pending starts and close their forwards when they complete, or prevent registration after shutdown.
…ying offline (STA-10476)
7266153 to
95c9898
Compare
…ying offline (STA-10476) (stablyai#28398) Co-authored-by: m4air <[email protected]> (cherry picked from commit 335cc32)
ELI5
For SSH hosts reached through a jump host or proxy, Orca opens a separate
sshprocess to tunnel to the host's Orca server, on a fixed port on this computer. Quitting Orca did not stop that process. On the next launch the port was still taken, so Orca marked the host offline, and Reconnect could not fix it. Now Orca stops these processes when it quits. If one was left behind anyway (crash, force-quit, or quitting an older Orca during an update), the next launch finds that leftover and stops it.What Changed
Before:
Local port 127.0.0.1:<port> is not available: EADDRINUSE.After: the host reconnects on relaunch.
Mechanism:
Quit. The SSH shutdown step now also closes every SSH port forward and every managed-server tunnel. It waits until each
ssh -Lprocess has exited, within the existing 6 s SSH quit budget; stopping already escalates to SIGKILL after 2 s.shutdown()also supersedes any tunnel build still in flight.Launch. When binding a fixed forward port fails with EADDRINUSE, Orca reads the process table once. It looks for a leftover Orca forward on that port, stops it (SIGTERM), and tries the port once more. A process qualifies only if:
sshexecutable is exactly what Orca would spawn for this same forward. That means the same options, the same-L 127.0.0.1:<port>:<remote>, and the same destination; onlyExitOnForwardFailure=yes|nomay differ, so a forward from an older version also matches. Any extra option means it is someone else's ssh.systemd --usersubreaper. On Windows, the parent pid is missing or now names a younger process.Orca escalates to SIGKILL only if the same pid still matches and its start time is readable and unchanged. A pid reused after SIGTERM is never signalled again.
As a result, a user's own
sshand a tunnel owned by another running Orca are never touched. If nothing qualifies, the original error stands.Why
ws://127.0.0.1:<port>), and the environment store checks that the tunnel and the pairing agree. Changing it means rewriting stored pairings on every connect.Linked Issue
STA-10476
Visual Proof
N/A — no UI change; the host simply stays online across restarts.
Testing
ssh -N -L 127.0.0.1:47120process was reparented to pid 1 and kept the port.reserveLocalForwardPort(47120)loggedStopping a forward a previous Orca left on 127.0.0.1:47120, then bound the port. A userssh -N -L 127.0.0.1:47121running next to it was untouched.ExitOnForwardFailure=yes) was also recovered.SshPortForwardManager.closeAllcrosses connections and does not fire the closed callback.shutdownsupersedes a late build.pnpm tc:node, focused andsrc/main/{ipc,ssh,startup}tests (8515 passed), oxlint,pnpm run check:code-quality:changed,pnpm lintReview
Agent skill upstream boundary
Notes
psreader on macOS/Linux and the native Windows table, never from PowerShell.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)