From b2a15ec327ead1caf6d6983092dae17e09c88dd1 Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Mon, 1 Jan 2018 17:32:03 -0800 Subject: [PATCH] pkg/expect: fix deadlock in mac OS bufio.NewReader.ReadString blocks even when the process received syscall.SIGKILL. Remove ptyMu mutex and make ReadString return when *os.File is closed. Signed-off-by: Gyuho Lee --- pkg/expect/expect.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pkg/expect/expect.go b/pkg/expect/expect.go index fe27ef7fe..e0227986b 100644 --- a/pkg/expect/expect.go +++ b/pkg/expect/expect.go @@ -33,7 +33,6 @@ type ExpectProcess struct { fpty *os.File wg sync.WaitGroup - ptyMu sync.Mutex // protects accessing fpty cond *sync.Cond // for broadcasting updates are available mu sync.Mutex // protects lines and err lines []string @@ -76,9 +75,7 @@ func (ep *ExpectProcess) read() { printDebugLines := os.Getenv("EXPECT_DEBUG") != "" r := bufio.NewReader(ep.fpty) for ep.err == nil { - ep.ptyMu.Lock() l, rerr := r.ReadString('\n') - ep.ptyMu.Unlock() ep.mu.Lock() ep.err = rerr if l != "" { @@ -150,9 +147,7 @@ func (ep *ExpectProcess) close(kill bool) error { } err := ep.cmd.Wait() - ep.ptyMu.Lock() ep.fpty.Close() - ep.ptyMu.Unlock() ep.wg.Wait() if err != nil {