Skip to content

Commit

Permalink
Fix hang when container fails to start
Browse files Browse the repository at this point in the history
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
(cherry picked from commit 31644d5)
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
  • Loading branch information
laurazard committed May 7, 2024
1 parent 4cf5afa commit ccea7d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cli/command/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ func runContainer(ctx context.Context, dockerCli command.Cli, runOpts *runOption
defer closeFn()
}

statusChan := waitExitOrRemoved(ctx, apiClient, containerID, copts.autoRemove)
// New context here because we don't to cancel waiting on container exit/remove
// when we cancel attach, etc.
statusCtx, cancelStatusCtx := context.WithCancel(context.WithoutCancel(ctx))
defer cancelStatusCtx()
statusChan := waitExitOrRemoved(statusCtx, apiClient, containerID, copts.autoRemove)

// start the container
if err := apiClient.ContainerStart(ctx, containerID, container.StartOptions{}); err != nil {
Expand Down
1 change: 1 addition & 0 deletions cli/command/container/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func waitExitOrRemoved(ctx context.Context, apiClient client.APIClient, containe

statusC := make(chan int)
go func() {
defer close(statusC)
select {
case <-ctx.Done():
return
Expand Down

0 comments on commit ccea7d8

Please sign in to comment.