Skip to content

fix: pty.Start respects context on Windows too #7373

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 3 commits into from
May 3, 2023

Conversation

spikecurtis
Copy link
Contributor

respect for the cmd.Context in the pty library was inconsistent between platforms because in Windows we don't actually use exec to start the child process.

This corrects this platform inconsistency and removes the hacks we added to work around it.

Signed-off-by: Spike Curtis <spike@coder.com>
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Windows tests seem to be missing an import but looks good otherwise.

@@ -449,7 +449,7 @@ func (s *Server) CreateCommand(ctx context.Context, script string, env []string)
}
}

cmd := exec.CommandContext(ctx, shell, args...)
cmd := pty.CommandContext(ctx, shell, args...)
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: Perhaps we should discourage the use of non-context commands and rename this to pty.Command? Main reason stdlib has two is that it's a later addition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, but then it wouldn't be a drop-in replacement.

I like keeping the same API as the standard library so people will find it familiar, even though it's tempting to "improve" the API.

Signed-off-by: Spike Curtis <spike@coder.com>
Signed-off-by: Spike Curtis <spike@coder.com>
@spikecurtis spikecurtis merged commit 9c030a8 into main May 3, 2023
@spikecurtis spikecurtis deleted the spike/pty-windows-start-ctx branch May 3, 2023 07:43
@github-actions github-actions bot locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants