Skip to content

fix(connections): close SSH tunnel when a pending connection is cancelled (#1369)#1370

Merged
datlechin merged 1 commit into
mainfrom
fix/1369-ssh-tunnel-leak-on-cancel
May 21, 2026
Merged

fix(connections): close SSH tunnel when a pending connection is cancelled (#1369)#1370
datlechin merged 1 commit into
mainfrom
fix/1369-ssh-tunnel-leak-on-cancel

Conversation

@datlechin

Copy link
Copy Markdown
Member

Fixes #1369.

Cancelling a tunnelled connection while it was connecting could leave the SSH tunnel (local forward port + keep-alive task) open if the user did not retry. cancelEnsureConnected removed the session but never closed the tunnel, and the cancelled connect task deliberately leaves the connectionId-keyed tunnel alone so it cannot tear down a retry's tunnel (per #1367).

Change

cancelEnsureConnected now closes the SSH tunnel when the cancelled session has no driver, i.e. no live connection is using it.

Race safety

SSHTunnelManager is an actor and closeTunnel runs as a single atomic step (removeValue + close(), no suspension). The cancel path is scheduled the moment the connection is cancelled, before any retry starts its slower tunnel handshake, and a retry's createTunnel closes and replaces the tunnel for the same id anyway. So the cancel closes only the abandoned attempt's tunnel and cannot drop a newer one.

Tests

The teardown is a side effect on the SSHTunnelManager actor singleton with no injection seam, so it is not unit-tested here, consistent with the existing SSH tunnel code. Verified by build. Session-removal behaviour is unchanged and still covered by the #1358 tests.

@datlechin datlechin merged commit 49faa9e into main May 21, 2026
1 check passed
@datlechin datlechin deleted the fix/1369-ssh-tunnel-leak-on-cancel branch May 21, 2026 06:16
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.

SSH tunnel can leak when a tunnelled connection is cancelled without a retry

1 participant