Skip to content

fix: Add command to reconnecting PTY #1860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2022
Merged

fix: Add command to reconnecting PTY #1860

merged 1 commit into from
May 27, 2022

Conversation

kylecarbs
Copy link
Member

This fixes #1708 and opens the door for PTYs to execute
non-shell commands!

This fixes #1708 and opens the door for PTYs to execute
non-shell commands!
@kylecarbs kylecarbs requested a review from dwahler May 27, 2022 17:31
@kylecarbs kylecarbs self-assigned this May 27, 2022
@kylecarbs kylecarbs marked this pull request as ready for review May 27, 2022 17:31
//
// The command is optional and defaults to start a shell.
func (c *Conn) ReconnectingPTY(id string, height, width uint16, command string) (net.Conn, error) {
channel, err := c.CreateChannel(context.Background(), fmt.Sprintf("%s:%d:%d:%s", id, height, width, command), &peer.ChannelOptions{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about taking this opportunity to add a version indicator:

Suggested change
channel, err := c.CreateChannel(context.Background(), fmt.Sprintf("%s:%d:%d:%s", id, height, width, command), &peer.ChannelOptions{
channel, err := c.CreateChannel(context.Background(), fmt.Sprintf("v1:%s:%d:%d:%s", id, height, width, command), &peer.ChannelOptions{

and a corresponding check in handleReconnectingPTY?

Without it, this change makes it much harder to ever add a fifth field in the future, because we wouldn't be able to reliably distinguish a 5-field label from a 4-field one whose "command" field contains a colon. And since we're passing the command directly to the shell, it seems like a situation where an incorrect parse could have bad consequences.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm seems like this surfaces the greater issue of incompatibility with agent<->coder versions. I'm nervous about versioning this because it really masks the greater problem.

Am I understanding that correctly? If so, I can create an issue for enforcing some level of compatibility between versions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely agree that this is just the tip of a bigger issue that we don't need to worry about solving right now. I just think that adding some kind of version indicator now -- no matter how simple -- will be enough to avoid painting ourselves into a corner.

The current version can use "too many colons" as an indicator that there's a version mismatch, and at least crash rather than silently doing the wrong thing, but this patch gets rid of that possibility.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding some kind of version indicator now

Or more accurately, adding it before people start seriously using v2 in production. Doesn't have to be literally now, so it's not really a blocker for this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough

@kylecarbs kylecarbs merged commit d0ed107 into main May 27, 2022
@kylecarbs kylecarbs deleted the reconpty branch May 27, 2022 19:51
kylecarbs added a commit that referenced this pull request Jun 10, 2022
This fixes #1708 and opens the door for PTYs to execute
non-shell commands!
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.

TestAgent/ReconnectingPTY fails using the fish shell
2 participants