Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: add Transport.MaxIdleConns limit #15461

bradfitz opened this issue Apr 27, 2016 · 3 comments

net/http: add Transport.MaxIdleConns limit #15461

bradfitz opened this issue Apr 27, 2016 · 3 comments


Copy link

@bradfitz bradfitz commented Apr 27, 2016

There's been a long-standing TODO in net/http.Transport that says:

type Transport struct {
    // TODO: tunable on global max cached connections

This bug is about that.

We already have Transport.MaxIdleConnsPerHost, but it's been requested by many (and again recently) that we have a Transport.MaxIdleConns for any host.

In the process, I also noticed that we're not aggressively removing cached connections when the peer server disconnects. We only lazily clean them up from the idle structures, which means we can hold onto memory for the bufio.Readers/Writers for a long time, wasting memory.

/cc @adg

@bradfitz bradfitz self-assigned this Apr 27, 2016
@bradfitz bradfitz added this to the Go1.7 milestone Apr 27, 2016
Copy link

@adg adg commented Apr 27, 2016

So MaxIdleConns would limit the total number of idle connections across all hosts? SGTM.

Copy link

@gopherbot gopherbot commented Apr 27, 2016

CL mentions this issue.

gopherbot pushed a commit that referenced this issue Apr 27, 2016
…r closes

Previously the Transport would cache idle connections from the
Transport for later reuse, but if a peer server disconnected
(e.g. idle timeout), we would not proactively remove the *persistConn
from the Transport's idle list, leading to a waste of memory
(potentially forever).

Instead, when the persistConn's readLoop terminates, remote it from
the idle list, if present.

This also adds the beginning of accounting for the total number of
idle connections, which will be needed for Transport.MaxIdleConns

Updates #15461

Change-Id: Iab091f180f8dd1ee0d78f34b9705d68743b5557b
Reviewed-by: Andrew Gerrand <>
Copy link

@gopherbot gopherbot commented Apr 30, 2016

CL mentions this issue.

@gopherbot gopherbot closed this in 81b2ea4 May 1, 2016
@golang golang locked and limited conversation to collaborators May 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.