Skip to content

feat(ssh): cancellable connection attempts#66

Open
BungeeDEV wants to merge 1 commit into
macnev2013:mainfrom
BungeeDEV:feat/ssh-cancel-connect
Open

feat(ssh): cancellable connection attempts#66
BungeeDEV wants to merge 1 commit into
macnev2013:mainfrom
BungeeDEV:feat/ssh-cancel-connect

Conversation

@BungeeDEV

Copy link
Copy Markdown
Contributor

This pull request adds support for cancelling in-progress SSH connection attempts from the frontend, improving the user experience when connecting to SSH hosts. The changes introduce a new cancellation mechanism on both the backend (Rust) and frontend (React/TypeScript), allowing users to abort SSH handshakes cleanly and avoid ghost sessions or lingering handles. Additionally, the UI now provides a Cancel button during connection attempts, and Escape key handling is improved for cancelling or closing dialogs.

SSH Connection Cancellation Support

Backend (Rust):

  • Added a new ssh_cancel_connect Tauri command and corresponding handler in SshManager, allowing the frontend to abort an in-flight SSH connection attempt via a frontend-supplied attempt_id. The backend races the handshake against a cancellation token, ensuring no ghost sessions are left on cancellation. [1] [2] [3] [4] [5] [6] [7]
  • Modified all SSH connect commands (including saved hosts and no-PTY variants) to accept an optional attempt_id parameter, wiring it through to the manager for cancellation support. [1] [2] [3] [4] [5]
  • Added a new SshError::Cancelled variant to signal when a connection attempt was cancelled, and updated serialization for error reporting. [1] [2]

Frontend (React/TypeScript):

  • Updated the ConnectionDialog component to support an onCancel callback, display a Cancel button while connecting, and use Escape to cancel or close as appropriate. [1] [2]
  • Refactored connection logic in HostsDashboard to generate a unique attemptId per connect attempt, provide a cancel function that calls the backend cancel command, and clean up UI state and backend sessions if cancelled. [1] [2] [3] [4] [5] [6] [7]

These changes ensure that users can abort SSH connection attempts responsively, and the backend will not leave any partial or ghost sessions if a connection is cancelled.

Let the user abort an in-flight SSH/SFTP connection from the connecting
dialog instead of waiting for the handshake to time out.

Backend:
- SshManager tracks in-flight attempts by a frontend-supplied attempt_id
  in a `pending_connects` map. connect / connect_no_pty race establish +
  PTY-open against a CancellationToken; on cancel the future is dropped
  mid-await so partial handles tear down and nothing is inserted into
  `sessions` (no ghost session).
- New ssh_cancel_connect command + SshError::Cancelled ("cancelled").
- attempt_id threaded through ssh_connect / connect_saved_host /
  connect_saved_host_no_pty; pf_start_tunnel passes None.

Frontend:
- HostsDashboard generates an attempt_id per connect/explore/recent flow,
  exposes a cancel() that calls ssh_cancel_connect and disconnects if the
  session settled in the race window.
- ConnectionDialog shows a Cancel button while connecting; Escape cancels
  during connect and closes in the error state.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@BungeeDEV BungeeDEV marked this pull request as ready for review June 7, 2026 19:11
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