Fix hang when container fails to start

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
(cherry picked from commit 31644d5ea7)
Signed-off-by: Laura Brehm <laurabrehm@hey.com>
This commit is contained in:
Laura Brehm 2024-05-05 22:45:37 +01:00
parent 4cf5afaefa
commit ccea7d8a30
No known key found for this signature in database
GPG Key ID: CFBF847B4A313468
2 changed files with 6 additions and 1 deletions

View File

@ -186,7 +186,11 @@ func runContainer(ctx context.Context, dockerCli command.Cli, runOpts *runOption
defer closeFn() 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 // start the container
if err := apiClient.ContainerStart(ctx, containerID, container.StartOptions{}); err != nil { if err := apiClient.ContainerStart(ctx, containerID, container.StartOptions{}); err != nil {

View File

@ -36,6 +36,7 @@ func waitExitOrRemoved(ctx context.Context, apiClient client.APIClient, containe
statusC := make(chan int) statusC := make(chan int)
go func() { go func() {
defer close(statusC)
select { select {
case <-ctx.Done(): case <-ctx.Done():
return return