waitExitOrRemoved: Handle context cancellation

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski 2024-04-29 16:33:03 +02:00
parent 9714adc6c7
commit 840016ea05
No known key found for this signature in database
GPG Key ID: B85EFCFE26DEF92A
1 changed files with 6 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package container
import (
"context"
"errors"
"strconv"
"github.com/docker/docker/api/types"
@ -36,6 +37,8 @@ func waitExitOrRemoved(ctx context.Context, apiClient client.APIClient, containe
statusC := make(chan int)
go func() {
select {
case <-ctx.Done():
return
case result := <-resultC:
if result.Error != nil {
logrus.Errorf("Error waiting for container: %v", result.Error.Message)
@ -44,6 +47,9 @@ func waitExitOrRemoved(ctx context.Context, apiClient client.APIClient, containe
statusC <- int(result.StatusCode)
}
case err := <-errC:
if errors.Is(err, context.Canceled) {
return
}
logrus.Errorf("error waiting for container: %v", err)
statusC <- 125
}