Repository navigation
Conversation
runWithPTY waited only for the pty to close, which happens when the child exits. If the client's connection closed while the child was still running, nothing told the child, so it and its pty stayed around until the tailcat server exited. OpenSSH hangs up the terminal in that case. Send SIGHUP to the child's process group when the session's context is canceled. The child is started with Setsid, so its process group ID is its PID. The watcher is stopped before cmd.Wait reaps the child, so it can't signal a process group ID that has since been reused. This covers connections that are closed. A client that vanishes without closing its connection (killed together with its tailcat ProxyCommand, or a dropped network) is never noticed by the server at all, PTY or not; that needs some kind of keepalive and isn't addressed here. The Windows ConPTY path is unchanged. The new TestSSHPTYHangupOnDisconnect fails on main (the child is still running 10s after the client closes its connection) and passes with this change. Fixes tailscale#214 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: AllenYen <20695184+tntrock@users.noreply.github.com>
This branch has not been deployed
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.
runWithPTY waited only for the pty to close, which happens when the child exits. If the client's connection closed while the child was still running, nothing told the child, so it and its pty stayed around until the tailcat server exited. OpenSSH hangs up the terminal in that case.
Send SIGHUP to the child's process group when the session's context is canceled. The child is started with Setsid, so its process group ID is its PID. The watcher is stopped before cmd.Wait reaps the child, so it can't signal a process group ID that has since been reused.
This covers connections that are closed. A client that vanishes without closing its connection (killed together with its tailcat ProxyCommand, or a dropped network) is never noticed by the server at all, PTY or not; that needs some kind of keepalive and isn't addressed here. The Windows ConPTY path is unchanged.
The new TestSSHPTYHangupOnDisconnect fails on main (the child is still running 10s after the client closes its connection) and passes with this change.
Tested end-to-end with the tailcat CLI and OpenSSH 9.6: 10 PTY clients whose ssh was killed left 10 processes and 10 ptys behind on main, and none with this change.
Fixes #214
🤖 Generated with Claude Code