Skip to content

Commit f8abd50

Browse files
committed
Fix darwin file descriptor error
1 parent 1a2344f commit f8abd50

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pty/start_other.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"os/exec"
99
"runtime"
10+
"strings"
1011
"syscall"
1112

1213
"github.com/creack/pty"
@@ -28,6 +29,12 @@ func startPty(cmd *exec.Cmd) (PTY, *os.Process, error) {
2829
err = cmd.Start()
2930
if err != nil {
3031
_ = ptty.Close()
32+
if runtime.GOOS == "darwin" && strings.Contains(err.Error(), "bad file descriptor") {
33+
// MacOS has an obscure issue where the PTY occasionally closes
34+
// before it's used. It's unknown why this is, but creating a new
35+
// TTY resolves it.
36+
return startPty(cmd)
37+
}
3138
return nil, nil, xerrors.Errorf("start: %w", err)
3239
}
3340
go func() {

0 commit comments

Comments
 (0)