Skip to content

Commit 0e7e1b9

Browse files
authored
Remove redundant goroutine while removing containers (docker#10449)
don't use goroutine to stop container while removing Signed-off-by: TP-O <[email protected]>
1 parent af6f0ff commit 0e7e1b9

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

pkg/compose/down.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -237,21 +237,25 @@ func (s *composeService) removeVolume(ctx context.Context, id string, w progress
237237
return err
238238
}
239239

240+
func (s *composeService) stopContainer(ctx context.Context, w progress.Writer, container moby.Container, timeout *time.Duration) error {
241+
eventName := getContainerProgressName(container)
242+
w.Event(progress.StoppingEvent(eventName))
243+
timeoutInSecond := utils.DurationSecondToInt(timeout)
244+
err := s.apiClient().ContainerStop(ctx, container.ID, containerType.StopOptions{Timeout: timeoutInSecond})
245+
if err != nil {
246+
w.Event(progress.ErrorMessageEvent(eventName, "Error while Stopping"))
247+
return err
248+
}
249+
w.Event(progress.StoppedEvent(eventName))
250+
return nil
251+
}
252+
240253
func (s *composeService) stopContainers(ctx context.Context, w progress.Writer, containers []moby.Container, timeout *time.Duration) error {
241254
eg, ctx := errgroup.WithContext(ctx)
242255
for _, container := range containers {
243256
container := container
244257
eg.Go(func() error {
245-
eventName := getContainerProgressName(container)
246-
w.Event(progress.StoppingEvent(eventName))
247-
timeoutInSecond := utils.DurationSecondToInt(timeout)
248-
err := s.apiClient().ContainerStop(ctx, container.ID, containerType.StopOptions{Timeout: timeoutInSecond})
249-
if err != nil {
250-
w.Event(progress.ErrorMessageEvent(eventName, "Error while Stopping"))
251-
return err
252-
}
253-
w.Event(progress.StoppedEvent(eventName))
254-
return nil
258+
return s.stopContainer(ctx, w, container, timeout)
255259
})
256260
}
257261
return eg.Wait()
@@ -263,10 +267,8 @@ func (s *composeService) removeContainers(ctx context.Context, w progress.Writer
263267
container := container
264268
eg.Go(func() error {
265269
eventName := getContainerProgressName(container)
266-
w.Event(progress.StoppingEvent(eventName))
267-
err := s.stopContainers(ctx, w, []moby.Container{container}, timeout)
270+
err := s.stopContainer(ctx, w, container, timeout)
268271
if err != nil {
269-
w.Event(progress.ErrorMessageEvent(eventName, "Error while Stopping"))
270272
return err
271273
}
272274
w.Event(progress.RemovingEvent(eventName))

0 commit comments

Comments
 (0)