From ce160b37e15ddb86c45314d080718f833e551aa3 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Tue, 31 May 2016 17:47:39 -0700 Subject: [PATCH] Wait for containerd to die before restarting it Signed-off-by: Kenfe-Mickael Laventure --- libcontainerd/remote_linux.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libcontainerd/remote_linux.go b/libcontainerd/remote_linux.go index d19372d7bd..bad7a58ec8 100644 --- a/libcontainerd/remote_linux.go +++ b/libcontainerd/remote_linux.go @@ -50,6 +50,7 @@ type remote struct { eventTsPath string pastEvents map[string]*containerd.Event runtimeArgs []string + daemonWaitCh chan struct{} } // New creates a fresh instance of libcontainerd remote. @@ -129,6 +130,7 @@ func (r *remote) handleConnectionChange() { transientFailureCount = 0 if utils.IsProcessAlive(r.daemonPid) { utils.KillProcess(r.daemonPid) + <-r.daemonWaitCh } if err := r.runContainerdDaemon(); err != nil { //FIXME: Handle error logrus.Errorf("error restarting containerd: %v", err) @@ -388,7 +390,11 @@ func (r *remote) runContainerdDaemon() error { return err } - go cmd.Wait() // Reap our child when needed + r.daemonWaitCh = make(chan struct{}) + go func() { + cmd.Wait() + close(r.daemonWaitCh) + }() // Reap our child when needed r.daemonPid = cmd.Process.Pid return nil }