From 1b215eb8731f072a00274e47f345ca9875f0168f Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 4 Sep 2018 12:04:35 -0700 Subject: [PATCH] Add fail fast path when containerd fails on startup Prevents looping of startup errors such as containerd not being found on the path. Signed-off-by: Derek McGowan (cherry picked from commit ce0b0b72bcc58de82ba1e0e7127499d07f678122) Signed-off-by: Sebastiaan van Stijn Upstream-commit: 85361af1f749517c8bdfd3d36b0df94a92e29b2b Component: engine --- .../libcontainerd/supervisor/remote_daemon.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/components/engine/libcontainerd/supervisor/remote_daemon.go b/components/engine/libcontainerd/supervisor/remote_daemon.go index 182984aeca..1dcfbe176b 100644 --- a/components/engine/libcontainerd/supervisor/remote_daemon.go +++ b/components/engine/libcontainerd/supervisor/remote_daemon.go @@ -43,7 +43,7 @@ type remote struct { logger *logrus.Entry daemonWaitCh chan struct{} - daemonStartCh chan struct{} + daemonStartCh chan error daemonStopCh chan struct{} rootDir string @@ -72,7 +72,7 @@ func Start(ctx context.Context, rootDir, stateDir string, opts ...DaemonOpt) (Da pluginConfs: pluginConfigs{make(map[string]interface{})}, daemonPid: -1, logger: logrus.WithField("module", "libcontainerd"), - daemonStartCh: make(chan struct{}), + daemonStartCh: make(chan error, 1), daemonStopCh: make(chan struct{}), } @@ -92,7 +92,10 @@ func Start(ctx context.Context, rootDir, stateDir string, opts ...DaemonOpt) (Da select { case <-time.After(startupTimeout): return nil, errors.New("timeout waiting for containerd to start") - case <-r.daemonStartCh: + case err := <-r.daemonStartCh: + if err != nil { + return nil, err + } } return r, nil @@ -269,7 +272,11 @@ func (r *remote) monitorDaemon(ctx context.Context) { os.RemoveAll(r.GRPC.Address) if err := r.startContainerd(); err != nil { - r.logger.WithError(err).Error("failed starting containerd") + if !started { + r.daemonStartCh <- err + return + } + r.logger.WithError(err).Error("failed restarting containerd") delay = time.After(50 * time.Millisecond) continue }