Browse code

Attach stdin after attach stdout/err to avoid an rpc lock

Reason of the lock is currently unknown

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>

Kenfe-Mickael Laventure authored on 2016/07/27 11:17:22
Showing 1 changed files
... ...
@@ -125,6 +125,23 @@ func (daemon *Daemon) AttachStreams(id string, iop libcontainerd.IOPipe) error {
125 125
 		}
126 126
 	}
127 127
 
128
+	copyFunc := func(w io.Writer, r io.Reader) {
129
+		s.Add(1)
130
+		go func() {
131
+			if _, err := io.Copy(w, r); err != nil {
132
+				logrus.Errorf("%v stream copy error: %v", id, err)
133
+			}
134
+			s.Done()
135
+		}()
136
+	}
137
+
138
+	if iop.Stdout != nil {
139
+		copyFunc(s.Stdout(), iop.Stdout)
140
+	}
141
+	if iop.Stderr != nil {
142
+		copyFunc(s.Stderr(), iop.Stderr)
143
+	}
144
+
128 145
 	if stdin := s.Stdin(); stdin != nil {
129 146
 		if iop.Stdin != nil {
130 147
 			go func() {
... ...
@@ -144,22 +161,5 @@ func (daemon *Daemon) AttachStreams(id string, iop libcontainerd.IOPipe) error {
144 144
 		}
145 145
 	}
146 146
 
147
-	copyFunc := func(w io.Writer, r io.Reader) {
148
-		s.Add(1)
149
-		go func() {
150
-			if _, err := io.Copy(w, r); err != nil {
151
-				logrus.Errorf("%v stream copy error: %v", id, err)
152
-			}
153
-			s.Done()
154
-		}()
155
-	}
156
-
157
-	if iop.Stdout != nil {
158
-		copyFunc(s.Stdout(), iop.Stdout)
159
-	}
160
-	if iop.Stderr != nil {
161
-		copyFunc(s.Stderr(), iop.Stderr)
162
-	}
163
-
164 147
 	return nil
165 148
 }