Skip to content

fix: TTY being GC'd before command is ran #412

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 2 commits into from
Mar 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pty/start_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package pty
import (
"os"
"os/exec"
"runtime"
"syscall"

"github.com/creack/pty"
Expand All @@ -29,6 +30,13 @@ func startPty(cmd *exec.Cmd) (PTY, *os.Process, error) {
_ = ptty.Close()
return nil, nil, xerrors.Errorf("start: %w", err)
}
go func() {
// The GC can garbage collect the TTY FD before the command
// has finished running. See:
// https://github.com/creack/pty/issues/127#issuecomment-932764012
Comment on lines +34 to +36
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice find 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a craaaazy race

_ = cmd.Wait()
runtime.KeepAlive(ptty)
}()
oPty := &otherPty{
pty: ptty,
tty: tty,
Expand Down