@@ -21,6 +21,7 @@ import (
21
21
"fmt"
22
22
"os"
23
23
"os/signal"
24
+ "sync/atomic"
24
25
"syscall"
25
26
26
27
"github.com/compose-spec/compose-go/v2/types"
@@ -29,6 +30,7 @@ import (
29
30
"github.com/docker/compose/v2/internal/tracing"
30
31
"github.com/docker/compose/v2/pkg/api"
31
32
"github.com/docker/compose/v2/pkg/progress"
33
+ "github.com/docker/docker/errdefs"
32
34
"github.com/eiannone/keyboard"
33
35
"github.com/hashicorp/go-multierror"
34
36
"github.com/sirupsen/logrus"
@@ -106,6 +108,9 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
106
108
}
107
109
}
108
110
}
111
+
112
+ // killRunning is used to control that we don't run more than one kill if signals are spammed.
113
+ var killRunning atomic.Bool
109
114
for {
110
115
select {
111
116
case <- doneCh :
@@ -117,19 +122,27 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
117
122
case <- signalChan :
118
123
if first {
119
124
gracefulTeardown ()
120
- } else {
121
- eg .Go (func () error {
122
- // Intentionally ignore errors, for cases where some
123
- // of the containers are already stopped.
124
- s .kill (context .Background (), project .Name , api.KillOptions {
125
- Services : options .Create .Services ,
126
- Project : project ,
127
- All : true ,
128
- })
129
- return nil
130
- })
131
- return nil
125
+ break
126
+ }
127
+ if ! killRunning .CompareAndSwap (false , true ) {
128
+ break
132
129
}
130
+ eg .Go (func () error {
131
+ defer killRunning .Store (false )
132
+ // Intentionally ignore errors, for cases where some
133
+ // of the containers are already stopped.
134
+ err := s .kill (context .Background (), project .Name , api.KillOptions {
135
+ Services : options .Create .Services ,
136
+ Project : project ,
137
+ All : true ,
138
+ })
139
+ // Ignore errors indicating that some of the containers were already stopped or removed.
140
+ if errdefs .IsNotFound (err ) || errdefs .IsConflict (err ) {
141
+ return nil
142
+ }
143
+
144
+ return err
145
+ })
133
146
case event := <- kEvents :
134
147
formatter .KeyboardManager .HandleKeyEvents (event , ctx , project , options )
135
148
}
0 commit comments