Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 6941445

Browse files
authored
Merge pull request #1544 from docker/race_condition
2 parents 1dc0c4c + 0ab75d2 commit 6941445

File tree

5 files changed

+15
-20
lines changed

5 files changed

+15
-20
lines changed

local/compose/containers.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ func (s *composeService) getContainers(ctx context.Context, project string, oneO
4343
f := filters.NewArgs(
4444
projectFilter(project),
4545
)
46+
if len(selectedServices) == 1 {
47+
f.Add("label", fmt.Sprintf("%s=%s", serviceLabel, selectedServices[0]))
48+
}
4649
switch oneOff {
4750
case oneOffOnly:
4851
f.Add("label", fmt.Sprintf("%s=%s", oneoffLabel, "True"))
@@ -57,7 +60,7 @@ func (s *composeService) getContainers(ctx context.Context, project string, oneO
5760
if err != nil {
5861
return nil, err
5962
}
60-
if len(selectedServices) > 0 {
63+
if len(selectedServices) > 1 {
6164
containers = containers.filter(isService(selectedServices...))
6265
}
6366
return containers, nil

local/compose/convergence.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,14 @@ func (s *composeService) connectContainerToNetwork(ctx context.Context, id strin
337337
}
338338

339339
func (s *composeService) isServiceHealthy(ctx context.Context, project *types.Project, service string) (bool, error) {
340-
containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
341-
Filters: filters.NewArgs(
342-
projectFilter(project.Name),
343-
serviceFilter(service),
344-
),
345-
})
340+
containers, err := s.getContainers(ctx, project.Name, oneOffExclude, false, service)
346341
if err != nil {
347342
return false, err
348343
}
349344

345+
if len(containers) == 0 {
346+
return false, nil
347+
}
350348
for _, c := range containers {
351349
container, err := s.apiClient.ContainerInspect(ctx, c.ID)
352350
if err != nil {
@@ -355,10 +353,7 @@ func (s *composeService) isServiceHealthy(ctx context.Context, project *types.Pr
355353
if container.State == nil || container.State.Health == nil {
356354
return false, fmt.Errorf("container for service %q has no healthcheck configured", service)
357355
}
358-
switch container.State.Health.Status {
359-
case "starting":
360-
return false, nil
361-
case "unhealthy":
356+
if container.State.Health.Status != moby.Healthy {
362357
return false, nil
363358
}
364359
}

local/compose/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (s *composeService) Exec(ctx context.Context, project *types.Project, opts
8383
defer resp.Close()
8484

8585
if opts.Tty {
86-
err := s.monitorTTySize(ctx, exec.ID, s.apiClient.ContainerExecResize)
86+
s.monitorTTySize(ctx, exec.ID, s.apiClient.ContainerExecResize)
8787
if err != nil {
8888
return err
8989
}

local/compose/resize.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ import (
2828
"github.com/docker/docker/pkg/signal"
2929
)
3030

31-
func (s *composeService) monitorTTySize(ctx context.Context, container string, resize func(context.Context, string, moby.ResizeOptions) error) error {
31+
func (s *composeService) monitorTTySize(ctx context.Context, container string, resize func(context.Context, string, moby.ResizeOptions) error) {
3232
err := resize(ctx, container, moby.ResizeOptions{ // nolint:errcheck
3333
Height: uint(goterm.Height()),
3434
Width: uint(goterm.Width()),
3535
})
3636
if err != nil {
37-
return err
37+
return
3838
}
3939

4040
sigchan := make(chan os.Signal, 1)
@@ -71,5 +71,4 @@ func (s *composeService) monitorTTySize(ctx context.Context, container string, r
7171
}
7272
}
7373
}()
74-
return nil
7574
}

local/compose/run.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,15 @@ func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.
8989
}
9090
defer restore()
9191

92+
statusC, errC := s.apiClient.ContainerWait(context.Background(), oneoffContainer.ID, container.WaitConditionNextExit)
93+
9294
err = s.apiClient.ContainerStart(ctx, containerID, apitypes.ContainerStartOptions{})
9395
if err != nil {
9496
return 0, err
9597
}
9698

97-
err = s.monitorTTySize(ctx, containerID, s.apiClient.ContainerResize)
98-
if err != nil {
99-
return 0, err
100-
}
99+
s.monitorTTySize(ctx, containerID, s.apiClient.ContainerResize)
101100

102-
statusC, errC := s.apiClient.ContainerWait(context.Background(), oneoffContainer.ID, container.WaitConditionNotRunning)
103101
select {
104102
case status := <-statusC:
105103
return int(status.StatusCode), nil

0 commit comments

Comments
 (0)