Skip to content

fix(ssh): a restore racing a disconnect never leaves a forward behind - #27368

Merged
OrcaWin merged 1 commit into
mainfrom
OrcaWin/blk2-port-restore-race
Oct 11, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
OrcaWin/blk2-port-restore-race

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​43 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​41
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​12 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10

ELI5

Orca reopens your saved SSH port forwards when a managed host reconnects. If you disconnected or removed that host while Orca was still reopening them, one forward could survive and keep a local port and an SSH login open until Orca quit. Now that forward is closed.

What Changed

Before: Orca restores saved forwards one at a time. Disconnecting or removing a host closes only the forwards that exist at that moment. A forward whose setup finished just after that got registered anyway. With the system SSH transport, setup takes about 750 ms per forward, so the window was real. The leftover was an ssh -L process holding the local port, and a later reconnect treated it as live.

After:

  • restorePortForwards checks the connection again after each forward is added. If the host disconnected or reconnected meanwhile, it closes the forward it just added and stops.
  • A queued managed-host restore checks that the host is still managed when it actually runs, not only when it was queued.

Why

Both checks sit where the race happens, so teardown does not need to wait for or cancel an in-flight restore. The alternative was having teardown wait for in-flight restores. That would make every disconnect wait up to a few seconds on forwards being set up. Found by the post-merge review of #27361.

Linked Issue

N/A (maintainer). Follow-up to #27361.

Visual Proof

N/A. This is a background race with no visible UI.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Two new unit tests failed before the fix:

  • a forward whose add completes after the disconnect is closed
  • a queued managed restore is skipped once the host is no longer managed

pnpm tc, pnpm lint and check:code-quality:changed pass.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

The relay restore path shares restorePortForwards, so it gets the same guard. There are no wire changes.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 77369889-2031-401c-a033-0e742daf0d70

📥 Commits

Reviewing files that changed from the base of the PR and between 5f350a3 and c78e0a7.


📒 Files selected for processing (3)
  • src/main/ipc/ssh-managed-port-forward-restore.ts
  • src/main/ipc/ssh-port-forward-persistence.ts
  • src/main/ipc/ssh-port-forward-restore.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.



📝 Walkthrough

Walkthrough

The restore flow now removes a forward if the target connection changes while the forward is added. Queued restores now skip hosts that are no longer managed. Tests cover both asynchronous race conditions and update the port-forward manager mock.


Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to c78e0

The changed restore paths address the identified disconnect and host-removal races. No concrete merge-blocking issue remains after normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary fix: preventing SSH port forwards from remaining after a restore races with disconnect.
Description check Passed The description is complete and focused. It explains the user impact, technical changes, rationale, tests, visual-proof exception, and checklist items. It does not report manual testing and does not e…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@OrcaWin
OrcaWin merged commit 22bcda1 into main Oct 11, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant