Skip to content

Commit

Permalink
container.runContainer(): call the cancel func
Browse files Browse the repository at this point in the history
Switch from x/net/context to context made "go vet" see the previously
unseen error:

> cli/command/container/run.go:159::error: the cancelFun function is not
> used on all paths (possible context leak) (vet)
> cli/command/container/run.go:164::error: this return statement may be
> reached without using the cancelFun var defined on line 159 (vet)

As the cancelFun is only used for an attached container, use
context.WithCancel conditionally.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed May 7, 2018
1 parent 8c37660 commit 9ef5c0c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cli/command/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
hostConfig.ConsoleSize[0], hostConfig.ConsoleSize[1] = dockerCli.Out().GetTtySize()
}

ctx, cancelFun := context.WithCancel(context.Background())
ctx := context.Background()
attach := config.AttachStdin || config.AttachStdout || config.AttachStderr
var cancelFun context.CancelFunc
if attach {
ctx, cancelFun = context.WithCancel(ctx)
}

createResponse, err := createContainer(ctx, dockerCli, containerConfig, &opts.createOptions)
if err != nil {
Expand All @@ -180,7 +185,6 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
fmt.Fprintln(stdout, createResponse.ID)
}()
}
attach := config.AttachStdin || config.AttachStdout || config.AttachStderr
if attach {
if opts.detachKeys != "" {
dockerCli.ConfigFile().DetachKeys = opts.detachKeys
Expand Down

0 comments on commit 9ef5c0c

Please sign in to comment.