mirror of https://github.com/docker/cli.git
waitExitOrRemoved: Handle context cancellation
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
parent
9714adc6c7
commit
840016ea05
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue