Skip to content

Commit

Permalink
Use context.WithCancel for potentially long operations
Browse files Browse the repository at this point in the history
  • Loading branch information
evol262 authored and Ryan Barry committed Aug 17, 2022
1 parent 10797dc commit 460da8e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions libdocker/kube_docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (d *kubeDockerClient) PullImage(
return err
}
opts.RegistryAuth = base64Auth
ctx, cancel := context.WithTimeout(context.Background(), d.timeout)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
resp, err := d.client.ImagePull(ctx, image, opts)
if err != nil {
Expand Down Expand Up @@ -446,7 +446,7 @@ func (d *kubeDockerClient) Logs(
opts dockertypes.ContainerLogsOptions,
sopts StreamOptions,
) error {
ctx, cancel := context.WithTimeout(context.Background(), d.timeout)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
resp, err := d.client.ContainerLogs(ctx, id, opts)
if ctxErr := contextError(ctx); ctxErr != nil {
Expand Down Expand Up @@ -511,7 +511,7 @@ func (d *kubeDockerClient) StartExec(
opts dockertypes.ExecStartCheck,
sopts StreamOptions,
) error {
ctx, cancel := context.WithTimeout(context.Background(), d.timeout)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if opts.Detach {
err := d.client.ContainerExecStart(ctx, startExec, opts)
Expand Down Expand Up @@ -567,7 +567,7 @@ func (d *kubeDockerClient) AttachToContainer(
opts dockertypes.ContainerAttachOptions,
sopts StreamOptions,
) error {
ctx, cancel := context.WithTimeout(context.Background(), d.timeout)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
resp, err := d.client.ContainerAttach(ctx, id, opts)
if ctxErr := contextError(ctx); ctxErr != nil {
Expand All @@ -587,7 +587,7 @@ func (d *kubeDockerClient) AttachToContainer(
}

func (d *kubeDockerClient) ResizeExecTTY(id string, height, width uint) error {
ctx, cancel := context.WithTimeout(context.Background(), d.timeout)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
return d.client.ContainerExecResize(ctx, id, dockertypes.ResizeOptions{
Height: height,
Expand All @@ -596,7 +596,7 @@ func (d *kubeDockerClient) ResizeExecTTY(id string, height, width uint) error {
}

func (d *kubeDockerClient) ResizeContainerTTY(id string, height, width uint) error {
ctx, cancel := context.WithTimeout(context.Background(), d.timeout)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
return d.client.ContainerResize(ctx, id, dockertypes.ResizeOptions{
Height: height,
Expand All @@ -606,7 +606,7 @@ func (d *kubeDockerClient) ResizeContainerTTY(id string, height, width uint) err

// GetContainerStats is currently only used for Windows container stats
func (d *kubeDockerClient) GetContainerStats(id string) (*dockertypes.StatsJSON, error) {
ctx, cancel := context.WithTimeout(context.Background(), d.timeout)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

response, err := d.client.ContainerStats(ctx, id, false)
Expand Down

0 comments on commit 460da8e

Please sign in to comment.