Skip to content

fix(ssh): bound the connect and tear down a connect that outlives its tab - #10

Open
andreas-byfut wants to merge 1 commit into
LordOfPolls:masterfrom
andreas-byfut:fix/ssh-connect-cancel-timeout
Open

andreas-byfut wants to merge 1 commit into
LordOfPolls:masterfrom
andreas-byfut:fix/ssh-connect-cancel-timeout

Conversation

@andreas-byfut

@andreas-byfut andreas-byfut commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Closing a tab while it was still CONNECTING could leave the connection attempt running:

  • A disconnect() that ran before ssh.connect() started had no socket to close.
  • With ProxyJump, a close during the chain left the chain dialling and authenticating, including
    host-key and keyboard-interactive prompts for a tab that was already closed. The final client
    was never closed.

Changes:

  • connectChainAndAuthenticate takes an isClosing check and polls it before each hop and
    before the final channel. On close it throws IOException and cleans up what it opened.
  • connect() re-checks the close flag once the transport is up and runs the existing teardown.
  • The TCP connect gets a 15 s timeout (CONNECT_TIMEOUT_MS). Before, a black-holed host held the
    session in CONNECTING until the OS gave up retrying SYN.

Known limits:

  • A hop that is already connecting or authenticating when the tab closes is not interrupted. The
    chain stops at the next hop boundary.
  • The timeout covers the TCP connect only. Key exchange keeps sshj's own limit.

Tests: ConnectTimeoutTest.

… tab

Closing a tab while it was CONNECTING could leave the attempt running.
disconnect() that ran before ssh.connect() started had no socket to
close, and one that ran during a ProxyJump chain had no chain resources
to tear down yet; the chain kept dialling, authenticating and prompting
for a closed tab, and the final client was never closed.

connectChainAndAuthenticate now polls a closing check before each hop,
and connect() re-checks it once the transport is up and runs the
existing teardown path. A hop already in flight is not interrupted.

The TCP connect also had no timeout, so a black-holed host kept the
session in CONNECTING for the OS's SYN retry limit. Set a 15s connect
timeout.
@andreas-byfut andreas-byfut changed the title fix(ssh): bound the connect and tear down a connect that outlives its tab fix(ssh): bound the connect and tear down a connect that outlives its tab Nov 13, 2026
@LordOfPolls

Copy link
Copy Markdown
Owner

Thanks. Fix looks solid but needs some revisions.

  • ConnectTimeoutTest uses PromiscuousVerifier. A stub verifier that rejects everything works just as well here, please revise. Using PromiscuousVerifier is not recommended because it accepts all host keys without verification, which poses significant security risk
  • Nothing tests isClosing at the hop boundary. A ServerSocket hop with isClosing = { true }, expecting an IOException and no accepted connection, would cover it.
  • Check isClosing() at the top of connectChainAndAuthenticate too, so a tab closed before a direct connect can't still raise a host-key or keyboard-interactive prompt.
  • ScriptRunner's capture watchdog has the same problem: it only disconnects the final client. Passing isClosing = { timedOut } (with timedOut made @Volatile) fixes it.
  • Mark chainResources @Volatile.

@LordOfPolls LordOfPolls added bug Something isn't working needs-revision labels Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working needs-revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants