diff --git a/pkg/virtctl/console/console.go b/pkg/virtctl/console/console.go index c1c2a747e06e..010c7f9df205 100644 --- a/pkg/virtctl/console/console.go +++ b/pkg/virtctl/console/console.go @@ -92,8 +92,8 @@ func (c *Console) Run(flags *flag.FlagSet) int { resChan := make(chan error) stopChan := make(chan struct{}, 1) - writeStop := make(chan struct{}) - readStop := make(chan struct{}) + writeStop := make(chan error) + readStop := make(chan error) go func() { err := virtCli.VM(namespace).SerialConsole(vm, device, stdinReader, stdoutWriter) @@ -108,8 +108,8 @@ func (c *Console) Run(flags *flag.FlagSet) int { }() go func() { - defer close(readStop) - io.Copy(out, stdoutReader) + _, err := io.Copy(out, stdoutReader) + readStop <- err }() go func() { @@ -119,6 +119,7 @@ func (c *Console) Run(flags *flag.FlagSet) int { // reading from stdin n, err := in.Read(buf) if err != nil && err != io.EOF { + writeStop <- err return } if n == 0 && err == io.EOF { @@ -139,8 +140,8 @@ func (c *Console) Run(flags *flag.FlagSet) int { select { case <-stopChan: - case <-readStop: - case <-writeStop: + case err = <-readStop: + case err = <-writeStop: case err = <-resChan: } diff --git a/pkg/virtctl/vnc/vnc.go b/pkg/virtctl/vnc/vnc.go index 634f5adef81e..5e8b00a41c50 100644 --- a/pkg/virtctl/vnc/vnc.go +++ b/pkg/virtctl/vnc/vnc.go @@ -67,8 +67,8 @@ func (o *VNC) Run(flags *flag.FlagSet) int { k8ResChan := make(chan error) viewResChan := make(chan error) stopChan := make(chan struct{}, 1) - writeStop := make(chan struct{}) - readStop := make(chan struct{}) + writeStop := make(chan error) + readStop := make(chan error) // The local tcp server is used to proxy the podExec websock connection to remote-viewer ln, err := net.Listen("tcp", "127.0.0.1:0") @@ -113,20 +113,20 @@ func (o *VNC) Run(flags *flag.FlagSet) int { // write to FD <- pipeOutReader go func() { - defer close(readStop) - io.Copy(fd, pipeOutReader) + _, err := io.Copy(fd, pipeOutReader) + readStop <- err }() // read from FD -> pipeInWriter go func() { - defer close(writeStop) - io.Copy(pipeInWriter, fd) + _, err := io.Copy(pipeInWriter, fd) + writeStop <- err }() select { case <-stopChan: - case <-readStop: - case <-writeStop: + case err = <-readStop: + case err = <-writeStop: case err = <-k8ResChan: case err = <-viewResChan: }