node-http-proxy icon indicating copy to clipboard operation
node-http-proxy copied to clipboard

Proxy websocket causes file descriptor leak

Open pxgo opened this issue 3 years ago • 3 comments

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?

pxgo avatar Mar 04 '21 05:03 pxgo

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

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

823639792 avatar Jul 05 '21 03:07 823639792

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

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

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

pxgo avatar Jul 15 '21 01:07 pxgo

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

823639792 avatar Jul 15 '21 01:07 823639792