Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions hypervisor/vm_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func streamCopy(tty *TtyIO, stdinPipe io.WriteCloser, stdoutPipe, stderrPipe io.
var wg sync.WaitGroup
// old way cleanup all(expect stdinPipe) no matter what kinds of fails, TODO: change it
var once sync.Once
// cleanup closes tty.Stdin and thus terminates the first go routine
cleanup := func() {
tty.Close()
// stdinPipe is directly closed in the first go routine
Expand All @@ -181,30 +182,32 @@ func streamCopy(tty *TtyIO, stdinPipe io.WriteCloser, stdoutPipe, stderrPipe io.
}
}
if tty.Stdin != nil {
wg.Add(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove this one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm.... having read the commit message, looks reasonable...

go func() {
_, err := io.Copy(stdinPipe, tty.Stdin)
stdinPipe.Close()
if err != nil {
// we should not call cleanup when tty.Stdin reaches EOF
once.Do(cleanup)
}
wg.Done()
}()
}
if tty.Stdout != nil {
wg.Add(1)
go func() {
io.Copy(tty.Stdout, stdoutPipe)
once.Do(cleanup)
_, err := io.Copy(tty.Stdout, stdoutPipe)
if err != nil {
once.Do(cleanup)
}
wg.Done()
}()
}
if tty.Stderr != nil && stderrPipe != nil {
wg.Add(1)
go func() {
io.Copy(tty.Stderr, stderrPipe)
once.Do(cleanup)
_, err := io.Copy(tty.Stderr, stderrPipe)
if err != nil {
once.Do(cleanup)
}
wg.Done()
}()
}
Expand Down