Browse Source

fix sigint/sigterm support in logs --follow

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 3 months ago
parent
commit
4dd369bdcb
2 changed files with 4 additions and 1 deletions
  1. 1 0
      pkg/compose/logs.go
  2. 3 1
      pkg/compose/monitor.go

+ 1 - 0
pkg/compose/logs.go

@@ -104,6 +104,7 @@ func (s *composeService) Logs(
 			}
 		})
 		eg.Go(func() error {
+			// pass ctx so monitor will immediately stop on SIGINT
 			return monitor.Start(ctx)
 		})
 	}

+ 3 - 1
pkg/compose/monitor.go

@@ -79,7 +79,7 @@ func (c *monitor) Start(ctx context.Context) error {
 	}
 	restarting := utils.Set[string]{}
 
-	evtCh, errCh := c.api.Events(context.Background(), events.ListOptions{
+	evtCh, errCh := c.api.Events(ctx, events.ListOptions{
 		Filters: filters.NewArgs(
 			filters.Arg("type", "container"),
 			projectFilter(c.project)),
@@ -89,6 +89,8 @@ func (c *monitor) Start(ctx context.Context) error {
 			return nil
 		}
 		select {
+		case <-ctx.Done():
+			return nil
 		case err := <-errCh:
 			return err
 		case event := <-evtCh: