From dc211b178ad647d30c207324ec5510e927852c84 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Thu, 17 Dec 2020 10:31:47 +0100 Subject: [PATCH] Fixed race when down with multiple containers for one service Signed-off-by: Guillaume Tardif --- local/compose/down.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/local/compose/down.go b/local/compose/down.go index 0227ddb2d..704f832c0 100644 --- a/local/compose/down.go +++ b/local/compose/down.go @@ -91,16 +91,17 @@ func (s *composeService) Down(ctx context.Context, projectName string, options c func (s *composeService) removeContainers(ctx context.Context, w progress.Writer, eg *errgroup.Group, containers []moby.Container) error { for _, container := range containers { + toDelete := container eg.Go(func() error { - eventName := "Container " + getContainerName(container) + eventName := "Container " + getContainerName(toDelete) w.Event(progress.StoppingEvent(eventName)) - err := s.apiClient.ContainerStop(ctx, container.ID, nil) + err := s.apiClient.ContainerStop(ctx, toDelete.ID, nil) if err != nil { w.Event(progress.ErrorMessageEvent(eventName, "Error while Stopping")) return err } w.Event(progress.RemovingEvent(eventName)) - err = s.apiClient.ContainerRemove(ctx, container.ID, moby.ContainerRemoveOptions{}) + err = s.apiClient.ContainerRemove(ctx, toDelete.ID, moby.ContainerRemoveOptions{}) if err != nil { w.Event(progress.ErrorMessageEvent(eventName, "Error while Removing")) return err