Skip to content

Commit 9ef173a

Browse files
authored
log: fix race on container kill (docker#10459)
If we go to inspect a container that we got an event for and it no longer exists on the server, handle clean up without erroring out. Fixes docker#10373. Signed-off-by: Milas Bowman <[email protected]>
1 parent 1fb0c03 commit 9ef173a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

pkg/compose/start.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"strings"
2323
"time"
2424

25+
"github.com/docker/docker/errdefs"
26+
2527
"github.com/docker/compose/v2/pkg/api"
2628
"github.com/docker/compose/v2/pkg/progress"
2729
"github.com/docker/compose/v2/pkg/utils"
@@ -169,14 +171,16 @@ func (s *composeService) watchContainers(ctx context.Context, //nolint:gocyclo
169171
err := s.Events(ctx, projectName, api.EventsOptions{
170172
Services: services,
171173
Consumer: func(event api.Event) error {
172-
if event.Status == "destroy" {
173-
// This container can't be inspected, because it's gone.
174-
// It's already been removed from the watched map.
175-
return nil
176-
}
177-
178174
inspected, err := s.apiClient().ContainerInspect(ctx, event.Container)
179175
if err != nil {
176+
if errdefs.IsNotFound(err) {
177+
// it's possible to get "destroy" or "kill" events but not
178+
// be able to inspect in time before they're gone from the
179+
// API, so just remove the watch without erroring
180+
delete(watched, event.Container)
181+
expected = utils.Remove(expected, event.Container)
182+
return nil
183+
}
180184
return err
181185
}
182186
container := moby.Container{

0 commit comments

Comments
 (0)