mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
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 <gyuhox@gmail.com>
This commit is contained in:
parent
fdec12cc20
commit
b2a15ec327
@ -33,7 +33,6 @@ type ExpectProcess struct {
|
|||||||
fpty *os.File
|
fpty *os.File
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
|
|
||||||
ptyMu sync.Mutex // protects accessing fpty
|
|
||||||
cond *sync.Cond // for broadcasting updates are available
|
cond *sync.Cond // for broadcasting updates are available
|
||||||
mu sync.Mutex // protects lines and err
|
mu sync.Mutex // protects lines and err
|
||||||
lines []string
|
lines []string
|
||||||
@ -76,9 +75,7 @@ func (ep *ExpectProcess) read() {
|
|||||||
printDebugLines := os.Getenv("EXPECT_DEBUG") != ""
|
printDebugLines := os.Getenv("EXPECT_DEBUG") != ""
|
||||||
r := bufio.NewReader(ep.fpty)
|
r := bufio.NewReader(ep.fpty)
|
||||||
for ep.err == nil {
|
for ep.err == nil {
|
||||||
ep.ptyMu.Lock()
|
|
||||||
l, rerr := r.ReadString('\n')
|
l, rerr := r.ReadString('\n')
|
||||||
ep.ptyMu.Unlock()
|
|
||||||
ep.mu.Lock()
|
ep.mu.Lock()
|
||||||
ep.err = rerr
|
ep.err = rerr
|
||||||
if l != "" {
|
if l != "" {
|
||||||
@ -150,9 +147,7 @@ func (ep *ExpectProcess) close(kill bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := ep.cmd.Wait()
|
err := ep.cmd.Wait()
|
||||||
ep.ptyMu.Lock()
|
|
||||||
ep.fpty.Close()
|
ep.fpty.Close()
|
||||||
ep.ptyMu.Unlock()
|
|
||||||
ep.wg.Wait()
|
ep.wg.Wait()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user