Skip to content

determine if there are situations when io.CopyN is needed to reuse underlying TCP connection #1575

Open
@itsksaurabh

Description

@itsksaurabh

Currently, the Github client only closes the response body which can be seen at https://github.com/google/go-github/blob/master/github/github.go#L557 . The resp.Body.Close() makes the connection available for reuse by others using the same http.Client. It doesn’t close the underlying HTTP or TCP connection.

According to the official Go docs:
https://golang.org/pkg/net/http/#Body

// The http Client and Transport guarantee that Body is always
// non-nil, even on responses without a body or responses with
// a zero-length body. It is the caller's responsibility to
// close Body. The default HTTP client's Transport may not
// reuse HTTP/1.x "keep-alive" TCP connections if the Body is
// not read to completion and closed.

My proposal to solve the issue:

  • Read until Response is complete (i.e. ioutil.ReadAll(resp.Body) or similar)
  • Call Body.Close()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions