Skip to content

Commit

Permalink
cli/command/container: don't leak context
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 errors:

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

> 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)

Do call the cancel function.

Note we might end up calling it twice which is fine as long as I can see
from the Go 1.10 source code.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed May 11, 2018
1 parent 41d126a commit 3314457
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions cli/command/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
}

ctx, cancelFun := context.WithCancel(context.Background())
defer cancelFun()

createResponse, err := createContainer(ctx, dockerCli, containerConfig, &opts.createOptions)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cli/command/container/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func NewStartCommand(dockerCli command.Cli) *cobra.Command {
// nolint: gocyclo
func runStart(dockerCli command.Cli, opts *startOptions) error {
ctx, cancelFun := context.WithCancel(context.Background())
defer cancelFun()

if opts.attach || opts.openStdin {
// We're going to attach to a container.
Expand Down

0 comments on commit 3314457

Please sign in to comment.