From 737f4382893a17eb63fbb60986b347b7ef33da57 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 8 Mar 2022 17:15:39 +0000 Subject: [PATCH 1/2] fix: TTY being GC'd before command is ran --- pty/start_other.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pty/start_other.go b/pty/start_other.go index a527869e99178..bcd6da1c0eace 100644 --- a/pty/start_other.go +++ b/pty/start_other.go @@ -6,6 +6,7 @@ package pty import ( "os" "os/exec" + "runtime" "syscall" "github.com/creack/pty" @@ -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(tty) + }() oPty := &otherPty{ pty: ptty, tty: tty, From c97328a1236283e5552a57ec0732ae266d698b11 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 8 Mar 2022 17:37:44 +0000 Subject: [PATCH 2/2] Fix reference to tty --- pty/start_other.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pty/start_other.go b/pty/start_other.go index bcd6da1c0eace..197f3631a592a 100644 --- a/pty/start_other.go +++ b/pty/start_other.go @@ -35,7 +35,7 @@ func startPty(cmd *exec.Cmd) (PTY, *os.Process, error) { // has finished running. See: // https://github.com/creack/pty/issues/127#issuecomment-932764012 _ = cmd.Wait() - runtime.KeepAlive(tty) + runtime.KeepAlive(ptty) }() oPty := &otherPty{ pty: ptty,