Skip to content

cmd/vet: govet sometimes wrong about whether a context gets cancelled #29587

Description

@the80srobot

What version of Go are you using (go version)?

Not sure, it's a toolchain. Most likely 1.11.

Does this issue reproduce with the latest release?

Yes, as of 1.12beta.

What operating system and processor architecture are you using (go env)?

No idea, govet runs remotely on a language server.

What did you do?

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if true {
  // This makes govet think that the child context never gets cancelled,
  // when, in fact, it is cancelled by the parent's cancel().
  ctx, _ = context.WithTimeout(ctx, time.Second)
}

What did you expect to see?

govet should not claim that the child context leaks. (If it's a style question, it should be in the linter, not govet.)

What did you see instead?

govet incorrectly thinks the child context does not get cancelled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.help wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions