Merge pull request #5044 from vvoland/wait-cancel-noerror

[26.1 backport] waitExitOrRemoved: Handle context cancellation
This commit is contained in:
Paweł Gronowski 2024-04-29 17:46:55 +02:00 committed by GitHub
commit 1e6db5d24b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 0 deletions

View File

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