Skip to content

Commit 2dc1be1

Browse files
committed
cli/command/container: don't leak context
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>
1 parent d87715c commit 2dc1be1

2 files changed

Lines changed: 2 additions & 0 deletions

File tree

cli/command/container/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
157157
}
158158

159159
ctx, cancelFun := context.WithCancel(context.Background())
160+
defer cancelFun()
160161

161162
createResponse, err := createContainer(ctx, dockerCli, containerConfig, &opts.createOptions)
162163
if err != nil {

cli/command/container/start.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func NewStartCommand(dockerCli command.Cli) *cobra.Command {
5555
// nolint: gocyclo
5656
func runStart(dockerCli command.Cli, opts *startOptions) error {
5757
ctx, cancelFun := context.WithCancel(context.Background())
58+
defer cancelFun()
5859

5960
if opts.attach || opts.openStdin {
6061
// We're going to attach to a container.

0 commit comments

Comments
 (0)