Wait for client side copy goroutines to start
Make sure we wait for the client side copy goroutines to start coping from the fifos before returning from the function. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
bfd62ceba9
commit
06dc87ae59
10
io_unix.go
10
io_unix.go
@ -36,6 +36,7 @@ func copyIO(fifos *FIFOSet, ioset *ioSet, tty bool) (_ *wgCloser, err error) {
|
|||||||
var (
|
var (
|
||||||
f io.ReadWriteCloser
|
f io.ReadWriteCloser
|
||||||
set []io.Closer
|
set []io.Closer
|
||||||
|
cwg sync.WaitGroup
|
||||||
ctx, cancel = context.WithCancel(context.Background())
|
ctx, cancel = context.WithCancel(context.Background())
|
||||||
wg = &sync.WaitGroup{}
|
wg = &sync.WaitGroup{}
|
||||||
)
|
)
|
||||||
@ -52,9 +53,13 @@ func copyIO(fifos *FIFOSet, ioset *ioSet, tty bool) (_ *wgCloser, err error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
set = append(set, f)
|
set = append(set, f)
|
||||||
|
cwg.Add(1)
|
||||||
|
wg.Add(1)
|
||||||
go func(w io.WriteCloser) {
|
go func(w io.WriteCloser) {
|
||||||
|
cwg.Done()
|
||||||
io.Copy(w, ioset.in)
|
io.Copy(w, ioset.in)
|
||||||
w.Close()
|
w.Close()
|
||||||
|
wg.Done()
|
||||||
}(f)
|
}(f)
|
||||||
|
|
||||||
if f, err = fifo.OpenFifo(ctx, fifos.Out, syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700); err != nil {
|
if f, err = fifo.OpenFifo(ctx, fifos.Out, syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700); err != nil {
|
||||||
@ -62,7 +67,9 @@ func copyIO(fifos *FIFOSet, ioset *ioSet, tty bool) (_ *wgCloser, err error) {
|
|||||||
}
|
}
|
||||||
set = append(set, f)
|
set = append(set, f)
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
cwg.Add(1)
|
||||||
go func(r io.ReadCloser) {
|
go func(r io.ReadCloser) {
|
||||||
|
cwg.Done()
|
||||||
io.Copy(ioset.out, r)
|
io.Copy(ioset.out, r)
|
||||||
r.Close()
|
r.Close()
|
||||||
wg.Done()
|
wg.Done()
|
||||||
@ -75,12 +82,15 @@ func copyIO(fifos *FIFOSet, ioset *ioSet, tty bool) (_ *wgCloser, err error) {
|
|||||||
|
|
||||||
if !tty {
|
if !tty {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
cwg.Add(1)
|
||||||
go func(r io.ReadCloser) {
|
go func(r io.ReadCloser) {
|
||||||
|
cwg.Done()
|
||||||
io.Copy(ioset.err, r)
|
io.Copy(ioset.err, r)
|
||||||
r.Close()
|
r.Close()
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}(f)
|
}(f)
|
||||||
}
|
}
|
||||||
|
cwg.Wait()
|
||||||
return &wgCloser{
|
return &wgCloser{
|
||||||
wg: wg,
|
wg: wg,
|
||||||
dir: fifos.Dir,
|
dir: fifos.Dir,
|
||||||
|
Loading…
Reference in New Issue
Block a user