-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Prevent leak of file descriptors with multiple clients #1499
Conversation
Each client keeps alive up to 2 connections, so the number of clients created in the lifetime of an application must be constant to prevent exhaustion of file descriptors. The options to fix this are: - keep one global client (in this patch for HTTP) - do not keep connections open (in this patch for UNIX) - keep a global pool of clients - export and document a method to close connections that calls (*http.Transport).CloseIdleConnections - document that users can only instantiate a small number of clients during the lifetime of an application
Related to #1308. |
Hi @orivej - this looks like a good change, though we could get most of the benefit without disabling keepalives, since all API clients will share one underlying HTTP client by default. Wanted to see if you had some other rationale for including that, or if it was just an optimization. Thanks! |
I disable kept alive connections only for the UNIX socket client, since it is created anew for each Consul client. |
I reviewed the code and noticed that when A not so great but probably acceptable solution to add finalizers to new It seems to me that the proper way forward is to implement an |
Currently Travis tests fail with:
Although my local tests pass. Can Travis tests failure be related to this change? |
@orivej the Travis failures are definitely not related to your change - we've been having trouble with CI today so I've been running things locally as well. Looking at the UNIX socket code in the Go library I don't think there's actually any support for keepalives for those, so it's probably not necessary to change. I took a crack at doing pooling of all three of the cases here, drafting off your idea for the default transport variable and the other spots you identified - #1517. What do you think? |
Your patch looks good. (I assume that no one will need to create clients for unix sockets at an arbitrary number of different paths.) Note that
|
@orivej thanks for the clarification on the keepalives. Updating the insecure transport is a good improvement so I went ahead and added that and merged the change. |
I had missed some of the conversation around go-cleanhttp in other issues and didn't appreciate that we can probably fix this up at that level with a finalizer, so reverted #1517 for now while we check into that. That would be a better solution and simplify the API client code. I kicked this back open as a reminder to re-add the change to the insecure socket code, which is independent of that change, and to make sure things get resolved upstream before closing this down again. |
@orivej See fsouza/go-dockerclient#434 (comment) -- can we find a good way to fix this in |
Closing this now that there #1526 open to clean up the loose ends. |
Each HTTP client keeps alive up to 2 connections, so the number of clients created in the lifetime of an application must be constant to prevent exhaustion of file descriptors. The options to fix this are:
(*http.Transport).CloseIdleConnections()