-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Memory leak when using client.clone() for server (proxy) #1315
Comments
The |
The requests are always to the same host, http://localhost/ in this example. I will try to find out what happens on a cloned client and what exactly is growing in memory. |
After spending half an hour of adding
The hashmap of parked things is growing linearly with the requests performed. The only call to remove() entries form the parked HashMap is in the put() function of Pool, but it is never called. So maybe we need to clean up the parked HashMap in other places as well? |
Great work investigating this! Thanks! The "parked" senders are |
I'm writing a reverse proxy and use the HTTP client to connect to any upstream server. Code is in https://github.com/klausi/rustnish/blob/goal-06/src/lib.rs#L150 . The server is leaking memory so I must be doing something wrong.
Steps to reproduce:
Make sure you have any upstream HTTP service running locally on port 80, for example the default Apache install on Ubuntu which will give you a dummy page at http://localhost/
Run rustnish reverse proxy on port 9090:
Get PID of rustnish process and memory usage:
The 6th column is the memory usage of the process, something like 20124 (~20MB)
Fire 1 million requests at the reverse proxy with Apache Bench:
(This takes ~130 seconds on my computer)
Check memory usage again:
The 6th column should show something like 284920, which is ~280MB!
So although we do not cache any requests or keep them around otherwise memory usage is growing without freeing up anymore.
One solution to the problem is this patch:
Avoiding the client.clone() call fixes the memory leak but degrades the runtime performance. Apache Bench with 1 million requests took 220 seconds instead of 130 seconds before. So the client_clone() call seems to be the right thing to do, but the clones are not dropped correctly when one request handling is done?
The text was updated successfully, but these errors were encountered: