fix(ssh): stop reconnecting after the remote shell exits on purpose - #183
Merged
Conversation
With persistent sessions off, typing `exit` closed the channel and the frontend immediately reconnected, resurrecting the session the user had just ended (#180). Persistent sessions escaped it only by accident: their attach probe fails with SESSION_ENDED and tears the tab down. The close event carried no reason, so a deliberate exit and a dropped link looked identical. They are not: the far side sends an exit-status (or exit-signal) before closing a command that ran to completion, and sends neither when the link dies. Carry that flag on `ssh-closed-<id>` and end the session instead of reconnecting when it is set. Persistent sessions keep the old path: their tmux/screen wrapper also exits on a detach, so the attach probe stays the judge there. The three terminal views built the same `handleSessionClosed` deps object; they now share one `sessionClosed` helper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #180.
The bug
With Settings → Hosts → Persistent sessions off, typing
exitin an SSH terminal disconnected and then immediately reconnected to the same host. With persistent sessions on,exitbehaved correctly.Root cause
ssh-closed-<id>carried no reason for the close, sohandleSessionClosedtreated a deliberateexitexactly like a dropped link and started the reconnect backoff. Persistent sessions escaped it only by accident: their attach-only probe fails withSESSION_ENDED, which tears the tab down.A deliberate exit and a dropped link are distinguishable on the wire. Verified against a local sshd:
exitfrom an interactive shell →client_input_channel_req: channel 0 rtype exit-statusThe fix
channel_io.rsrecords anExitStatus/ExitSignalseen before Eof/Close and ships that flag as thessh-closed-<id>payload.handleSessionClosedends the session (disconnect + drop the tab, viacloseSession) instead of reconnecting when the flag is set — matching what persistent sessions already do when their session ends on the host.MainPanel,PaneTerminal,MobileSessionView) each built the same deps object; they now share onesessionClosedhelper.Tests
channel_io::tests::only_a_reported_exit_counts_as_a_remote_exit— exit-status/exit-signal count, Eof/Close/other messages do not.reconnectBackoff.test.ts— clean exit ends the session; clean exit on a persistent session still reconnects; a drop with no exit-status still reconnects.tsc --noEmitclean.Live run
Headless container on this branch, persistent sessions toggled off, real SSH host (
ssh-host-1):exit→ the connected session left the store within 1 s and stayed gone for the 13 s watched; its tab disappeared from the tab bar. No reconnect.kill -9on the remotesshd-sessionpids (a drop, no exit-status) → session wentconnectingat 2 s and back toconnectedat 4 s. Reconnect still works.