Skip to content

Commit

Permalink
Solve "Error: lostcancel: the cancel function returned by context.Wit…
Browse files Browse the repository at this point in the history
…hTimeout should be called, not discarded, to avoid a context leak (govet)".

Signed-off-by: zhaoyonghe <yonghe.zhao@yahoo.com>
  • Loading branch information
zhaoyonghe committed Nov 27, 2023
1 parent f2b584a commit 18dc8c7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cmd/cosign/cli/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ against the transparency log.`,
v.NameOptions = append(v.NameOptions, name.Insecure)
}

ctx, _ := context.WithTimeout(cmd.Context(), ro.Timeout)
ctx, cancel := context.WithTimeout(cmd.Context(), ro.Timeout)
defer cancel()

if o.CommonVerifyOptions.IgnoreTlog && !o.CommonVerifyOptions.PrivateInfrastructure {
ui.Warnf(ctx, fmt.Sprintf(ignoreTLogMessage, "signature"))
Expand Down Expand Up @@ -242,7 +243,8 @@ against the transparency log.`,
return fmt.Errorf("please set the --max-worker flag to a value that is greater than 0")
}

ctx, _ := context.WithTimeout(cmd.Context(), ro.Timeout)
ctx, cancel := context.WithTimeout(cmd.Context(), ro.Timeout)
defer cancel()

if o.CommonVerifyOptions.IgnoreTlog && !o.CommonVerifyOptions.PrivateInfrastructure {
ui.Warnf(ctx, fmt.Sprintf(ignoreTLogMessage, "attestation"))
Expand Down Expand Up @@ -337,7 +339,8 @@ The blob may be specified as a path to a file or - for stdin.`,
IgnoreTlog: o.CommonVerifyOptions.IgnoreTlog,
}

ctx, _ := context.WithTimeout(cmd.Context(), ro.Timeout)
ctx, cancel := context.WithTimeout(cmd.Context(), ro.Timeout)
defer cancel()

if o.CommonVerifyOptions.IgnoreTlog && !o.CommonVerifyOptions.PrivateInfrastructure {
ui.Warnf(ctx, fmt.Sprintf(ignoreTLogMessage, "blob"))
Expand Down Expand Up @@ -412,7 +415,8 @@ The blob may be specified as a path to a file.`,
path = args[0]
}

ctx, _ := context.WithTimeout(cmd.Context(), ro.Timeout)
ctx, cancel := context.WithTimeout(cmd.Context(), ro.Timeout)
defer cancel()

if o.CommonVerifyOptions.IgnoreTlog && !o.CommonVerifyOptions.PrivateInfrastructure {
ui.Warnf(ctx, fmt.Sprintf(ignoreTLogMessage, "blob attestation"))
Expand Down

0 comments on commit 18dc8c7

Please sign in to comment.