Skip to content

x/tools/go/analysis/passes/httpresponse: detect failure to call resp.Body.Close() #75902

@adonovan

Description

@adonovan

The caller of http.Get and friends has a documented responsibility to call resp.Body.Close() on the response. Failure to do so prevents the http package from reusing the transport. @prattmic recently found this to be the cause of a problem in a production service (Googlers: cl/815710818).

We should experiment with augmenting the existing httpresponse analyzer (which currently detects only overeager calls to resp.Body.Close before we've inspected the error returned by http.Get) so that it also reports failure to close the response body.

(Interestingly, @bradfitz also recently found a related issue in which failure to drain the response body, even in the HTTP error case, caused the http package to fail to recycle resources in a timely manner, even when the calling code had correctly remembered to defer a call to resp.Body.Close().)

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions