Skip to content

Commit

Permalink
recvtty: fix waiting for both goroutines
Browse files Browse the repository at this point in the history
It looks like we need to wait for the both copy goroutines to finish,
not just the one that happen to finish first.

Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed Nov 30, 2020
1 parent 1c0143d commit 5bfae52
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions contrib/cmd/recvtty/recvtty.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net"
"os"
"strings"
"sync"

"github.com/containerd/console"
"github.com/opencontainers/runc/libcontainer/utils"
Expand Down Expand Up @@ -110,20 +111,22 @@ func handleSingle(path string, noStdin bool) error {
}

// Copy from our stdio to the master fd.
quitChan := make(chan struct{})
var wg sync.WaitGroup
wg.Add(1)
go func() {
io.Copy(os.Stdout, c)
quitChan <- struct{}{}
wg.Done()
}()
if !noStdin {
wg.Add(1)
go func() {
io.Copy(c, os.Stdin)
quitChan <- struct{}{}
wg.Done()
}()
}

// Only close the master fd once we've stopped copying.
<-quitChan
wg.Wait()
c.Close()
return nil
}
Expand Down

0 comments on commit 5bfae52

Please sign in to comment.