-
Notifications
You must be signed in to change notification settings - Fork 871
Memory leak in http-proxy dependency when client closes connection prematurely #782
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
Comments
Unable to reproduce locally and in staging/production. using node 14 LTS AND HPM 1.0.3 We have a software in production that has been running OK without any leak for weeks now, with millions request / day. |
@audifaxdev I prepared a reproduction example here: You may run it locally or using docker-compose. Also, keep in mind that memory leak doesn't happen when all http requests are properly closed by clients. |
I just added a hotfix branch to my reproduction example repository to demonstrate that it fixes the memory leak in question |
Ideally, this issue should be addressed in http-proxy repository, not here. |
I observed a similar problem and this issue helped me to get a clue of the reason behind leaking sockets. I would love a fix for this issue. |
Would you guys perhaps want to try to use my package? it's basically http-proxy but incorporating most of the pull requests that looked useful. |
Oh man, for a couple of days I struggled with a hanging SSE connection on browser tab refresh. Thanks for hotfix, it definitely should be merged! |
Here is another fix for this memory leak: http-party/node-http-proxy#1559. It was published to npm as http-proxy-node16. |
@lbeschastny is this only an issue with node 15.15+, or is there memory leak in the older versions of node(node14) as well? |
@Muhammad-Ahmad-Rai I just run my reproduction example lbeschastny/http-proxy-memory-leak-example using Node.js v14.15 and it worked fine (no memory leaks). According to http-party/node-http-proxy#1559 this issue affects Node.js v15.5.0 and above. I'm not sure about Node.js v15.x prior to v15.5.0, though. |
|
Checks
http-proxy-middleware
.Describe the bug (be clear and concise)
This is an issue of http-proxy, but I decided to report it here as well because:
http-proxy-middleware
is affected by this issuehttp-proxy
version was released in 2020, so I don't expect them to fix it soonhttp-proxy-middleware
sideHere is a complete description of this issue: http-party/node-http-proxy#1586
Step-by-step reproduction instructions
Here is a minimal example to reproduce the above-mentioned memory leak:
I used http-server to create an upstream server:
npx http-server . -p 5000
Memory leak appears when client sends a http request, but then closes connection prematurely after receiving HTTP headers without waiting for HTTP body.
I used cURL to simulate this behavior:
Memory leak could be reproduces with cURL when requesting any binary file from a TTY terminal, since cURL doesn't support printing binary data to terminals and just closes the connection.
Expected behavior (be clear and concise)
Memory should not leak
How is http-proxy-middleware used in your project?
What http-proxy-middleware configuration are you using?
What OS/version and node/version are you seeing the problem?
Additional context (optional)
Here is a code I used to fix
http-proxy
memory leak in my project:The actual code could be simpler since:
'close'
events since they are always emitted after'error'
events (unlessemitClose
isfalse
)removeListener
manually, because those listeners should not prevent streams from being garbage collected (but who knows, I certainly don't want to test it)The text was updated successfully, but these errors were encountered: