Skip to content

Commit 45daa44

Browse files
authored
fix: TTY being GC'd before command is ran (coder#412)
* fix: TTY being GC'd before command is ran * Fix reference to tty
1 parent d37df89 commit 45daa44

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pty/start_other.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package pty
66
import (
77
"os"
88
"os/exec"
9+
"runtime"
910
"syscall"
1011

1112
"github.com/creack/pty"
@@ -29,6 +30,13 @@ func startPty(cmd *exec.Cmd) (PTY, *os.Process, error) {
2930
_ = ptty.Close()
3031
return nil, nil, xerrors.Errorf("start: %w", err)
3132
}
33+
go func() {
34+
// The GC can garbage collect the TTY FD before the command
35+
// has finished running. See:
36+
// https://github.com/creack/pty/issues/127#issuecomment-932764012
37+
_ = cmd.Wait()
38+
runtime.KeepAlive(ptty)
39+
}()
3240
oPty := &otherPty{
3341
pty: ptty,
3442
tty: tty,

0 commit comments

Comments
 (0)