Skip to content

Commit

Permalink
fix: TTY being GC'd before command is ran (#412)
Browse files Browse the repository at this point in the history
* fix: TTY being GC'd before command is ran

* Fix reference to tty
  • Loading branch information
kylecarbs committed Mar 8, 2022
1 parent d37df89 commit 45daa44
Showing 1 changed file with 8 additions and 0 deletions.
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
_ = cmd.Wait()
runtime.KeepAlive(ptty)
}()
oPty := &otherPty{
pty: ptty,
tty: tty,
Expand Down

0 comments on commit 45daa44

Please sign in to comment.