Skip to content

Commit

Permalink
log: fix race on container kill (#10459)
Browse files Browse the repository at this point in the history
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 #10373.

Signed-off-by: Milas Bowman <milas.bowman@docker.com>
  • Loading branch information
milas committed Apr 12, 2023
1 parent 1fb0c03 commit 9ef173a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/compose/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"strings"
"time"

"github.com/docker/docker/errdefs"

"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/progress"
"github.com/docker/compose/v2/pkg/utils"
Expand Down Expand Up @@ -169,14 +171,16 @@ func (s *composeService) watchContainers(ctx context.Context, //nolint:gocyclo
err := s.Events(ctx, projectName, api.EventsOptions{
Services: services,
Consumer: func(event api.Event) error {
if event.Status == "destroy" {
// This container can't be inspected, because it's gone.
// It's already been removed from the watched map.
return nil
}

inspected, err := s.apiClient().ContainerInspect(ctx, event.Container)
if err != nil {
if errdefs.IsNotFound(err) {
// it's possible to get "destroy" or "kill" events but not
// be able to inspect in time before they're gone from the
// API, so just remove the watch without erroring
delete(watched, event.Container)
expected = utils.Remove(expected, event.Container)
return nil
}
return err
}
container := moby.Container{
Expand Down

0 comments on commit 9ef173a

Please sign in to comment.