-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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 Client.CloseIdleConnections method #26563
Comments
@bcmills, doesn't seem like a dup of #21978. I suppose we could add a Close method on Client that just checks for its Transport having a Updating the Client documentation to mention Transport.CloseIdleConnections is awkward because https://golang.org/pkg/net/http/#Client.Transport is a |
How about we name the method "CloseIdleConnections" on Client and name the interface in httputil? Because "Close" almost implies too much: that it'd close in-flight response bodies, etc. |
No one seems to be objecting, so proposal approved. |
Change https://golang.org/cl/130115 mentions this issue: |
How about call the http.DefaultTransport.CloseIdleConnections when the Transport field is nil? |
@bronze1man, it does. |
Consider the following code:
I know that the *http.Client need to be closed or it will leak memory or connections in the process and make a out of memory error after create a lot of it.
It is too complex for a normal programmer to understand how to close a *http.Client (or even know that the *http.Client object need close).
So I think add a
func Close() error
method to it, should make the programmer think it looks like a *os.File, it need to be closed after using it.In our team, several new golang programmers made a out of memory and too many connections from creating too many *http.Client object, and forget to close it.
Here is a bug caused by *http.Client object manage:
softlayer/softlayer-go#88
There is not document of how to close a *http.Client, it just say
Clients should be reused instead of created as needed.
, it do not say the create a lot of *http.Client and do not close it will cause leak memory:https://golang.org/pkg/net/http/#Client
The text was updated successfully, but these errors were encountered: