mirror of https://github.com/docker/compose.git
log: fix race on container kill (#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 #10373. Signed-off-by: Milas Bowman <milas.bowman@docker.com>
This commit is contained in:
parent
1fb0c03e8b
commit
9ef173a3ac
|
@ -22,6 +22,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/docker/errdefs"
|
||||||
|
|
||||||
"github.com/docker/compose/v2/pkg/api"
|
"github.com/docker/compose/v2/pkg/api"
|
||||||
"github.com/docker/compose/v2/pkg/progress"
|
"github.com/docker/compose/v2/pkg/progress"
|
||||||
"github.com/docker/compose/v2/pkg/utils"
|
"github.com/docker/compose/v2/pkg/utils"
|
||||||
|
@ -169,14 +171,16 @@ func (s *composeService) watchContainers(ctx context.Context, //nolint:gocyclo
|
||||||
err := s.Events(ctx, projectName, api.EventsOptions{
|
err := s.Events(ctx, projectName, api.EventsOptions{
|
||||||
Services: services,
|
Services: services,
|
||||||
Consumer: func(event api.Event) error {
|
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)
|
inspected, err := s.apiClient().ContainerInspect(ctx, event.Container)
|
||||||
if err != nil {
|
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
|
return err
|
||||||
}
|
}
|
||||||
container := moby.Container{
|
container := moby.Container{
|
||||||
|
|
Loading…
Reference in New Issue