Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Fix short-lived invocation-image exec (#606)
Browse files Browse the repository at this point in the history
This reorders docker_driver operations, aligning with what does the docker CLI (attach, and setup wait channels before starting the container)

This fix an issue with very short lived image executions, where the container was removed before attaching/waiting for execution end.

Signed-off-by: Simon Ferquel <[email protected]>
  • Loading branch information
simonferquel authored and technosophos committed Jan 14, 2019
1 parent 2af5fe4 commit f4ced4a
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions pkg/driver/docker_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,6 @@ func (d *DockerDriver) exec(op *Operation) error {
return fmt.Errorf("error copying to / in container: %s", err)
}

if err = cli.Client().ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
return fmt.Errorf("cannot start container: %v", err)
}

attach, err := cli.Client().ContainerAttach(ctx, resp.ID, types.ContainerAttachOptions{
Stream: true,
Stdout: true,
Expand All @@ -182,16 +178,23 @@ func (d *DockerDriver) exec(op *Operation) error {
}
}()

statusc, errc := cli.Client().ContainerWait(ctx, resp.ID, container.WaitConditionNotRunning)
statusc, errc := cli.Client().ContainerWait(ctx, resp.ID, container.WaitConditionRemoved)
if err = cli.Client().ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
return fmt.Errorf("cannot start container: %v", err)
}
select {
case err := <-errc:
if err != nil {
return fmt.Errorf("error in container: %v", err)
}
case containerWaitOKBody := <-statusc:
if containerWaitOKBody.StatusCode != 0 {
return fmt.Errorf("container exited with status code: %v", containerWaitOKBody.StatusCode)
case s := <-statusc:
if s.StatusCode == 0 {
return nil
}
if s.Error != nil {
return fmt.Errorf("container exit code: %d, message: %v", s.StatusCode, s.Error.Message)
}
return fmt.Errorf("container exit code: %d", s.StatusCode)
}
return err
}
Expand Down

0 comments on commit f4ced4a

Please sign in to comment.