Browse code

Fix a rare segfault that can occur in service logs

Revendors swarmkit with a change that fixes a rare segfault that can
occur when following logs on a brand new service with bad bind mount
options.

Fixes docker/swarmkit#2147

Signed-off-by: Drew Erny <drew.erny@docker.com>

Drew Erny authored on 2017/04/28 07:51:38
Showing 2 changed files
... ...
@@ -105,7 +105,7 @@ github.com/docker/containerd 9048e5e50717ea4497b757314bad98ea3763c145
105 105
 github.com/tonistiigi/fifo 1405643975692217d6720f8b54aeee1bf2cd5cf4
106 106
 
107 107
 # cluster
108
-github.com/docker/swarmkit 78db8a5fed39c637dcd136b9e16c29f135b41c94
108
+github.com/docker/swarmkit bd105f8afe9609137a48f817ae124295df0e8ef1
109 109
 github.com/gogo/protobuf 8d70fb3182befc465c4a1eac8ad4d38ff49778e2
110 110
 github.com/cloudflare/cfssl 7fb22c8cba7ecaf98e4082d22d65800cf45e042a
111 111
 github.com/google/certificate-transparency d90e65c3a07988180c5b1ece71791c0b6506826e
... ...
@@ -426,14 +426,19 @@ func (w *worker) Listen(ctx context.Context, reporter StatusReporter) {
426 426
 }
427 427
 
428 428
 func (w *worker) startTask(ctx context.Context, tx *bolt.Tx, task *api.Task) error {
429
-	w.taskevents.Publish(task.Copy())
430 429
 	_, err := w.taskManager(ctx, tx, task) // side-effect taskManager creation.
431 430
 
432 431
 	if err != nil {
433 432
 		log.G(ctx).WithError(err).Error("failed to start taskManager")
433
+		// we ignore this error: it gets reported in the taskStatus within
434
+		// `newTaskManager`. We log it here and move on. If their is an
435
+		// attempted restart, the lack of taskManager will have this retry
436
+		// again.
437
+		return nil
434 438
 	}
435 439
 
436
-	// TODO(stevvooe): Add start method for taskmanager
440
+	// only publish if controller resolution was successful.
441
+	w.taskevents.Publish(task.Copy())
437 442
 	return nil
438 443
 }
439 444
 
... ...
@@ -464,7 +469,7 @@ func (w *worker) newTaskManager(ctx context.Context, tx *bolt.Tx, task *api.Task
464 464
 	}
465 465
 
466 466
 	if err != nil {
467
-		log.G(ctx).Error("controller resolution failed")
467
+		log.G(ctx).WithError(err).Error("controller resolution failed")
468 468
 		return nil, err
469 469
 	}
470 470
 
... ...
@@ -568,9 +573,14 @@ func (w *worker) Subscribe(ctx context.Context, subscription *api.SubscriptionMe
568 568
 		case v := <-ch:
569 569
 			task := v.(*api.Task)
570 570
 			if match(task) {
571
-				w.mu.Lock()
572
-				go w.taskManagers[task.ID].Logs(ctx, *subscription.Options, publisher)
573
-				w.mu.Unlock()
571
+				w.mu.RLock()
572
+				tm, ok := w.taskManagers[task.ID]
573
+				w.mu.RUnlock()
574
+				if !ok {
575
+					continue
576
+				}
577
+
578
+				go tm.Logs(ctx, *subscription.Options, publisher)
574 579
 			}
575 580
 		case <-ctx.Done():
576 581
 			return ctx.Err()