From 2bebacef5f354871c2882c76ab70529cb47ed7d3 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Mon, 25 Apr 2016 10:29:49 -0700 Subject: [PATCH] Wait for the reader fifo opening to block In a rare case exec process may return before open gets called and the io will lock indefinitely. Signed-off-by: Tonis Tiigi --- libcontainerd/process_linux.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libcontainerd/process_linux.go b/libcontainerd/process_linux.go index 136a6e250c..3c48576fe2 100644 --- a/libcontainerd/process_linux.go +++ b/libcontainerd/process_linux.go @@ -79,7 +79,9 @@ func (r emptyReader) Read(b []byte) (int, error) { func openReaderFromFifo(fn string) io.Reader { r, w := io.Pipe() + c := make(chan struct{}) go func() { + close(c) stdoutf, err := os.OpenFile(fn, syscall.O_RDONLY, 0) if err != nil { r.CloseWithError(err) @@ -90,6 +92,7 @@ func openReaderFromFifo(fn string) io.Reader { w.Close() stdoutf.Close() }() + <-c // wait for the goroutine to get scheduled and syscall to block return r }