Skip to content

Commit fb6d922

Browse files
authored
Merge pull request docker#11361 from laurazard/always-handle-signals
signals/utils: always handle received signals
2 parents d688d3b + 898e1b6 commit fb6d922

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

cmd/compose/compose.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import (
4242
"github.com/spf13/cobra"
4343
"github.com/spf13/pflag"
4444

45-
"github.com/docker/cli/cli-plugins/plugin"
4645
"github.com/docker/compose/v2/cmd/formatter"
4746
"github.com/docker/compose/v2/pkg/api"
4847
"github.com/docker/compose/v2/pkg/compose"
@@ -74,20 +73,17 @@ type CobraCommand func(context.Context, *cobra.Command, []string) error
7473
// AdaptCmd adapt a CobraCommand func to cobra library
7574
func AdaptCmd(fn CobraCommand) func(cmd *cobra.Command, args []string) error {
7675
return func(cmd *cobra.Command, args []string) error {
77-
ctx := cmd.Context()
78-
contextString := fmt.Sprintf("%s", ctx)
79-
if !strings.Contains(contextString, ".WithCancel") || plugin.RunningStandalone() { // need to handle cancel
80-
cancellableCtx, cancel := context.WithCancel(cmd.Context())
81-
ctx = cancellableCtx
82-
s := make(chan os.Signal, 1)
83-
signal.Notify(s, syscall.SIGTERM, syscall.SIGINT)
84-
go func() {
85-
<-s
86-
cancel()
87-
signal.Stop(s)
88-
close(s)
89-
}()
90-
}
76+
ctx, cancel := context.WithCancel(cmd.Context())
77+
78+
s := make(chan os.Signal, 1)
79+
signal.Notify(s, syscall.SIGTERM, syscall.SIGINT)
80+
go func() {
81+
<-s
82+
cancel()
83+
signal.Stop(s)
84+
close(s)
85+
}()
86+
9187
err := fn(ctx, cmd, args)
9288
var composeErr compose.Error
9389
if api.IsErrCanceled(err) || errors.Is(ctx.Err(), context.Canceled) {

0 commit comments

Comments
 (0)