diff --git a/agent/worker.go b/agent/worker.go index 212aa1e12f..efe538afa7 100644 --- a/agent/worker.go +++ b/agent/worker.go @@ -257,11 +257,13 @@ func reconcileTaskState(ctx context.Context, w *worker, assignments []*api.Assig } closeManager := func(tm *taskManager) { - defer w.closers.Done() - // when a task is no longer assigned, we shutdown the task manager - if err := tm.Close(); err != nil { - log.G(ctx).WithError(err).Error("error closing task manager") - } + go func(tm *taskManager) { + defer w.closers.Done() + // when a task is no longer assigned, we shutdown the task manager + if err := tm.Close(); err != nil { + log.G(ctx).WithError(err).Error("error closing task manager") + } + }(tm) // make an attempt at removing. this is best effort. any errors will be // retried by the reaper later.