소스 검색

Wait for the reader fifo opening to block

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Tonis Tiigi 9 년 전
부모
커밋
0b2023130e
2개의 변경된 파일5개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 1
      libcontainerd/container_linux.go
  2. 3 0
      libcontainerd/process_linux.go

+ 2 - 1
libcontainerd/container_linux.go

@@ -225,8 +225,9 @@ func (ctr *container) discardFifos() {
 		f := ctr.fifo(i)
 		c := make(chan struct{})
 		go func() {
+			r := openReaderFromFifo(f)
 			close(c) // this channel is used to not close the writer too early, before readonly open has been called.
-			io.Copy(ioutil.Discard, openReaderFromFifo(f))
+			io.Copy(ioutil.Discard, r)
 		}()
 		<-c
 		closeReaderFifo(f) // avoid blocking permanently on open if there is no writer side

+ 3 - 0
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
 }