From f725442e878b94db9cdc4570c79ffa4ef53e0127 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 25 Sep 2019 11:39:50 -0700 Subject: [PATCH] agent/reconcileTaskState: wait for closeManager Since commit be528e80a ("Bump Golang 1.12.9") test suite panics: > panic: Log in goroutine after TestWorkerUpdate has completed > > goroutine 1175 [running]: > testing.(*common).logDepth(0xc00019a100, 0xc0000396a0, 0x1d, 0x3) > /usr/local/go/src/testing/testing.go:634 +0x51a > testing.(*common).log(...) > /usr/local/go/src/testing/testing.go:614 > testing.(*common).Log(0xc00019a100, 0xc00006fb00, 0x1, 0x1) > /usr/local/go/src/testing/testing.go:642 +0x79 > github.com/docker/swarmkit/agent.(*mockTaskController).Remove(0xc00020a780, 0x13b6f40, 0xc0000b4010, 0x13b6f40, 0xc0000b4010) > /home/circleci/.go_workspace/src/github.com/docker/swarmkit/agent/worker_test.go:604 +0x8e > github.com/docker/swarmkit/agent.reconcileTaskState.func1(0xc0004dac60) > /home/circleci/.go_workspace/src/github.com/docker/swarmkit/agent/worker.go:270 +0x137 > created by github.com/docker/swarmkit/agent.reconcileTaskState > /home/circleci/.go_workspace/src/github.com/docker/swarmkit/agent/worker.go:313 +0x1a6f > FAIL github.com/docker/swarmkit/agent 4.244s > This is an attempt to fix this. Signed-off-by: Kir Kolyshkin --- agent/worker.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/agent/worker.go b/agent/worker.go index 212aa1e12f..f86940db80 100644 --- a/agent/worker.go +++ b/agent/worker.go @@ -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") @@ -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) } } @@ -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() }