Merge pull request #32905 from dperny/17.05.x-fix-agent-logs-segfault

[17.05.x] Cherry-pick: Fix a rare segfault that can occur in service logs
This commit is contained in:
Aaron Lehmann 2017-04-28 18:34:08 -07:00 committed by GitHub
commit a3600db8c5
2 changed files with 17 additions and 7 deletions

View File

@ -105,7 +105,7 @@ github.com/docker/containerd 9048e5e50717ea4497b757314bad98ea3763c145
github.com/tonistiigi/fifo 1405643975692217d6720f8b54aeee1bf2cd5cf4
# cluster
github.com/docker/swarmkit 78db8a5fed39c637dcd136b9e16c29f135b41c94
github.com/docker/swarmkit bd105f8afe9609137a48f817ae124295df0e8ef1
github.com/gogo/protobuf 8d70fb3182befc465c4a1eac8ad4d38ff49778e2
github.com/cloudflare/cfssl 7fb22c8cba7ecaf98e4082d22d65800cf45e042a
github.com/google/certificate-transparency d90e65c3a07988180c5b1ece71791c0b6506826e

View File

@ -426,14 +426,19 @@ func (w *worker) Listen(ctx context.Context, reporter StatusReporter) {
}
func (w *worker) startTask(ctx context.Context, tx *bolt.Tx, task *api.Task) error {
w.taskevents.Publish(task.Copy())
_, err := w.taskManager(ctx, tx, task) // side-effect taskManager creation.
if err != nil {
log.G(ctx).WithError(err).Error("failed to start taskManager")
// we ignore this error: it gets reported in the taskStatus within
// `newTaskManager`. We log it here and move on. If their is an
// attempted restart, the lack of taskManager will have this retry
// again.
return nil
}
// TODO(stevvooe): Add start method for taskmanager
// only publish if controller resolution was successful.
w.taskevents.Publish(task.Copy())
return nil
}
@ -464,7 +469,7 @@ func (w *worker) newTaskManager(ctx context.Context, tx *bolt.Tx, task *api.Task
}
if err != nil {
log.G(ctx).Error("controller resolution failed")
log.G(ctx).WithError(err).Error("controller resolution failed")
return nil, err
}
@ -568,9 +573,14 @@ func (w *worker) Subscribe(ctx context.Context, subscription *api.SubscriptionMe
case v := <-ch:
task := v.(*api.Task)
if match(task) {
w.mu.Lock()
go w.taskManagers[task.ID].Logs(ctx, *subscription.Options, publisher)
w.mu.Unlock()
w.mu.RLock()
tm, ok := w.taskManagers[task.ID]
w.mu.RUnlock()
if !ok {
continue
}
go tm.Logs(ctx, *subscription.Options, publisher)
}
case <-ctx.Done():
return ctx.Err()