@@ -33,7 +33,6 @@ import (
3333)
3434
3535func (s * composeService ) Down (ctx context.Context , projectName string , options compose.DownOptions ) error {
36- eg , _ := errgroup .WithContext (ctx )
3736 w := progress .ContextWriter (ctx )
3837
3938 if options .Project == nil {
@@ -55,25 +54,21 @@ func (s *composeService) Down(ctx context.Context, projectName string, options c
5554
5655 err = InReverseDependencyOrder (ctx , options .Project , func (c context.Context , service types.ServiceConfig ) error {
5756 serviceContainers , others := containers .split (isService (service .Name ))
58- err := s .removeContainers (ctx , w , eg , serviceContainers )
57+ err := s .removeContainers (ctx , w , serviceContainers )
5958 containers = others
6059 return err
6160 })
61+ if err != nil {
62+ return err
63+ }
6264
63- if options .RemoveOrphans {
64- err := s .removeContainers (ctx , w , eg , containers )
65+ if options .RemoveOrphans && len ( containers ) > 0 {
66+ err := s .removeContainers (ctx , w , containers )
6567 if err != nil {
6668 return err
6769 }
6870 }
6971
70- if err != nil {
71- return err
72- }
73- err = eg .Wait ()
74- if err != nil {
75- return err
76- }
7772 networks , err := s .apiClient .NetworkList (ctx , moby.NetworkListOptions {
7873 Filters : filters .NewArgs (
7974 projectFilter (projectName ),
@@ -82,14 +77,15 @@ func (s *composeService) Down(ctx context.Context, projectName string, options c
8277 if err != nil {
8378 return err
8479 }
80+
81+ eg , _ := errgroup .WithContext (ctx )
8582 for _ , n := range networks {
8683 networkID := n .ID
8784 networkName := n .Name
8885 eg .Go (func () error {
8986 return s .ensureNetworkDown (ctx , networkID , networkName )
9087 })
9188 }
92-
9389 return eg .Wait ()
9490}
9591
@@ -108,15 +104,14 @@ func (s *composeService) stopContainers(ctx context.Context, w progress.Writer,
108104 return nil
109105}
110106
111- func (s * composeService ) removeContainers (ctx context.Context , w progress.Writer , eg * errgroup.Group , containers []moby.Container ) error {
107+ func (s * composeService ) removeContainers (ctx context.Context , w progress.Writer , containers []moby.Container ) error {
108+ eg , _ := errgroup .WithContext (ctx )
112109 for _ , container := range containers {
113110 toDelete := container
114111 eg .Go (func () error {
115112 eventName := "Container " + getCanonicalContainerName (toDelete )
116- w .Event (progress .StoppingEvent (eventName ))
117113 err := s .stopContainers (ctx , w , []moby.Container {container })
118114 if err != nil {
119- w .Event (progress .ErrorMessageEvent (eventName , "Error while Stopping" ))
120115 return err
121116 }
122117 w .Event (progress .RemovingEvent (eventName ))
0 commit comments