Browse code

Merge pull request #37759 from dmcgowan/fix-libcontainerd-startup-error

Add fail fast path when containerd fails on startup

Sebastiaan van Stijn authored on 2018/09/14 22:15:38
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
... ...
@@ -269,7 +272,11 @@ func (r *remote) monitorDaemon(ctx context.Context) {
269 269
 
270 270
 			os.RemoveAll(r.GRPC.Address)
271 271
 			if err := r.startContainerd(); err != nil {
272
-				r.logger.WithError(err).Error("failed starting containerd")
272
+				if !started {
273
+					r.daemonStartCh <- err
274
+					return
275
+				}
276
+				r.logger.WithError(err).Error("failed restarting containerd")
273 277
 				delay = time.After(50 * time.Millisecond)
274 278
 				continue
275 279
 			}