Browse code

Merge pull request #23148 from mlaventure/wait-for-containerd-before-restarting-it

Wait for containerd to die before restarting it

Alexander Morozov authored on 2016/06/02 02:35:31
Showing 1 changed files
... ...
@@ -51,6 +51,7 @@ type remote struct {
51 51
 	eventTsPath   string
52 52
 	pastEvents    map[string]*containerd.Event
53 53
 	runtimeArgs   []string
54
+	daemonWaitCh  chan struct{}
54 55
 }
55 56
 
56 57
 // New creates a fresh instance of libcontainerd remote.
... ...
@@ -130,6 +131,7 @@ func (r *remote) handleConnectionChange() {
130 130
 					transientFailureCount = 0
131 131
 					if utils.IsProcessAlive(r.daemonPid) {
132 132
 						utils.KillProcess(r.daemonPid)
133
+						<-r.daemonWaitCh
133 134
 					}
134 135
 					if err := r.runContainerdDaemon(); err != nil { //FIXME: Handle error
135 136
 						logrus.Errorf("error restarting containerd: %v", err)
... ...
@@ -390,7 +392,11 @@ func (r *remote) runContainerdDaemon() error {
390 390
 		return err
391 391
 	}
392 392
 
393
-	go cmd.Wait() // Reap our child when needed
393
+	r.daemonWaitCh = make(chan struct{})
394
+	go func() {
395
+		cmd.Wait()
396
+		close(r.daemonWaitCh)
397
+	}() // Reap our child when needed
394 398
 	r.daemonPid = cmd.Process.Pid
395 399
 	return nil
396 400
 }