Skip to content

Core: close response body, when body is not used #1949

@kayrus

Description

@kayrus

While working on #1942 I noticed that in certain cases there can be a resource leak. E.g. in delete operations:

resp, err := c.Delete(deleteURL(c, id), nil)

When JSONResponse parameter is nil, the response body is not closed, therefore the existing connection cannot be reused.

See https://golang.org/pkg/net/http/#Client.Do

If the returned error is nil, the Response will contain a non-nil Body which the user is expected to close. If the Body is not both read to EOF and closed, the Client's underlying RoundTripper (typically Transport) may not be able to re-use a persistent TCP connection to the server for a subsequent "keep-alive" request.

@jtopjian is it something that should be considered or do I dramatize things?

Relates to #1015

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions