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

tcp sockets never destroyed

Open mrkiani98 opened this issue 3 years ago • 0 comments
trafficstars

Hi,

We're using http-proxy module to proxy requests to other modules ( we don't have websocket requests). The service is deployed on RKE. ( RKE v2.5.8, docker v20.10.7, ubuntu 20.04 ).

The problem is that we monitor the server and we found below details on server : a) 3000 allocated tcp sockets (90% of these allocated sockets are in the state "closed") b) tcp socket buffer size is almost ( 800 MB ) c) cpu usage of server goes to almost 100% and then server crashes ( means the web service does not reply and even we cannot ssh to server )

And whenever we redeploy the pod, all of the closed sockets will disappear. Seems the tcp sockets are getting closed but they never destroyed.

Here is the creation of proxy object in code :

const proxy = httpProxy.createProxyServer();
const proxyErrorHandler = (err, req, res) => {
  console.log(`Reporting 503 for Error ${err.stack || JSON.stringify(err)}\n
    Req headers: ${JSON.stringify(req.headers)}`);
  req.socket.destroy();
  res.status(503).send('Our servers are temporarily unavailable. Please try again later');
};
router.all('/api/example1*', verify, log, (req, res) => {
  proxy.web(req, res, { target: process.env.EXAMPLE_HOST, proxyErrorHandler);
});
.
.
.

Questions: 1- How should we destroy these closed sockets ? 2- Is it related to ubuntu kernel's parameters or code related issue ?

mrkiani98 avatar Jan 14 '22 05:01 mrkiani98