Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion agent/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,12 @@ func reconcileTaskState(ctx context.Context, w *worker, assignments []*api.Assig
assigned[task.ID] = struct{}{}
}

wg := sync.WaitGroup{}
closeManager := func(tm *taskManager) {
defer w.closers.Done()
defer func() {
w.closers.Done()
wg.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")
Expand Down Expand Up @@ -293,6 +297,7 @@ func reconcileTaskState(ctx context.Context, w *worker, assignments []*api.Assig
err := removeTaskAssignment(id)
if err == nil {
delete(w.taskManagers, id)
wg.Add(1)
go closeManager(tm)
}
}
Expand All @@ -308,11 +313,14 @@ func reconcileTaskState(ctx context.Context, w *worker, assignments []*api.Assig
tm, ok := w.taskManagers[task.ID]
if ok {
delete(w.taskManagers, task.ID)
wg.Add(1)
go closeManager(tm)
}
}
}

wg.Wait()

return tx.Commit()
}

Expand Down