http-party / node-http-proxy

A full-featured http proxy for node.js
https://github.com/http-party/node-http-proxy
Other
13.86k stars 1.96k forks source link

Proxy websocket causes file descriptor leak #1510

Open pxgo opened 3 years ago

pxgo commented 3 years ago

I have encountered a problem of file descriptor leakage. When the browser is forced to close after establishing multiple websocket connections, the number of file descriptors of the agent program will not decrease. Through the windows resource monitor, you can see that there are a large number of File \Device\Afd in the handles associated with the agent.

In the source code, when an error occurs in the socket from the client to the proxy, the code executes proxySocket.end(), the code is as follows:

// http-proxy/passes/ws-incoming.js:131
socket.on('error', function (err) {
   proxySocket.end();
});

The problem disappeared when I changed proxySocket.end() to proxySocket.destroy().

Excuse me, if you execute proxySocket.destroy(), will there be any other consequences?

823639792 commented 3 years ago

Same error. @pengxiguaa 你是怎么解决的?

我在尝试你的 proxySocket.end() to proxySocket.destroy()

pxgo commented 3 years ago

Same error. @pengxiguaa 你是怎么解决的?

我在尝试你的 proxySocket.end() to proxySocket.destroy()

我仅仅修改了 http-proxy/passes/ws-incoming.js:131 这一个地方,只是文件句柄数增加得更缓慢了,但并没有解决问题。

823639792 commented 3 years ago

我的测试结果也是这样的 部分时间是正常的,偶尔内存中Socket对象数就暴增,内存也就跟着暴涨,短时间内涨到1-2G 但通过JS的HeapDump看,JS中只占用了十几兆的内存~