Skip to content

Commit

Permalink
report io.Copy errors for virtctl vnc/console
Browse files Browse the repository at this point in the history
Signed-off-by: David Vossel <[email protected]>
  • Loading branch information
davidvossel committed Jan 4, 2018
1 parent 5a65533 commit c395771
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
13 changes: 7 additions & 6 deletions pkg/virtctl/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand All @@ -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 {
Expand All @@ -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:
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/virtctl/vnc/vnc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
}
Expand Down

0 comments on commit c395771

Please sign in to comment.