Skip to content

go vet should report an error when t.Context is used inside t.Cleanup #74539

Closed as not planned
@YairHalberstadt

Description

@YairHalberstadt

Since the context is closed before t.Cleanup is called this is almost always a mistake, and can usually be detected statically. It's an easy mistake to make, and on one occasion I wasted about an hour trying to find the root cause.

The minimum would be to detect a direct call to t.Context() in t.Cleanup. This could be improved by detecting usage of context.Context variable inside t.Cleanup which was ever assigned t.Context in the past. This should probably cover almost all such uses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions