Browse code

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 <derek@mcgstyle.net>

Derek McGowan authored on 2018/09/05 04:04:35
Showing 1 changed files
... ...
@@ -43,7 +43,7 @@ type remote struct {
43 43
 	logger    *logrus.Entry
44 44
 
45 45
 	daemonWaitCh  chan struct{}
46
-	daemonStartCh chan struct{}
46
+	daemonStartCh chan error
47 47
 	daemonStopCh  chan struct{}
48 48
 
49 49
 	rootDir     string
... ...
@@ -72,7 +72,7 @@ func Start(ctx context.Context, rootDir, stateDir string, opts ...DaemonOpt) (Da
72 72
 		pluginConfs:   pluginConfigs{make(map[string]interface{})},
73 73
 		daemonPid:     -1,
74 74
 		logger:        logrus.WithField("module", "libcontainerd"),
75
-		daemonStartCh: make(chan struct{}),
75
+		daemonStartCh: make(chan error, 1),
76 76
 		daemonStopCh:  make(chan struct{}),
77 77
 	}
78 78
 
... ...
@@ -92,7 +92,10 @@ func Start(ctx context.Context, rootDir, stateDir string, opts ...DaemonOpt) (Da
92 92
 	select {
93 93
 	case <-time.After(startupTimeout):
94 94
 		return nil, errors.New("timeout waiting for containerd to start")
95
-	case <-r.daemonStartCh:
95
+	case err := <-r.daemonStartCh:
96
+		if err != nil {
97
+			return nil, err
98
+		}
96 99
 	}
97 100
 
98 101
 	return r, nil
... ...
@@ -263,7 +266,11 @@ func (r *remote) monitorDaemon(ctx context.Context) {
263 263
 
264 264
 			os.RemoveAll(r.GRPC.Address)
265 265
 			if err := r.startContainerd(); err != nil {
266
-				r.logger.WithError(err).Error("failed starting containerd")
266
+				if !started {
267
+					r.daemonStartCh <- err
268
+					return
269
+				}
270
+				r.logger.WithError(err).Error("failed restarting containerd")
267 271
 				delay = time.After(50 * time.Millisecond)
268 272
 				continue
269 273
 			}