-
-
Notifications
You must be signed in to change notification settings - Fork 17.1k
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
Flooding requests results in memory leak #4936
Comments
Hi @VeryHamburger very sorry you are encountering this. We would love to help investigate. Is it possible to provide steps to reproduce that error message as well as the exact version of Node.js and Express.js you are using when it happens? Also, would it be possible to see if the following code still has the issue or not? const fs = require('fs');
const http = require('http');
const https = require('https');
const app = (req, res) => {
res.end(JSON.stringify({
message: 'Hello World!'
}));
};
const privateKey = fs.readFileSync('/etc/letsencrypt/live/.../privkey.pem', 'utf8');
const certificate = fs.readFileSync('/etc/letsencrypt/live/.../cert.pem', 'utf8');
const ca = fs.readFileSync('/etc/letsencrypt/live/.../chain.pem', 'utf8');
const credentials = {
key: privateKey,
cert: certificate,
ca: ca
};
const httpServer = http.createServer(app);
const httpsServer = https.createServer(credentials, app);
httpServer.listen(80, () => {
console.log('HTTP Server running on port 80');
});
httpsServer.listen(443, () => {
console.log('HTTPS Server running on port 443');
}); |
My Node.js version is To reproduce the error message on the code I was using, you would have to use a stress tester and run it for around |
Thank you. I tried a stress tester, |
I'm using this site which only requires an account to use and is free to use. Layer 7 If you don't get an error, you might have to run it again. |
Thank you, I will try that tomorrow (it is past 1am my time). In the meanwhile, can you start your server with https://nodejs.org/dist/latest-v18.x/docs/api/cli.html#--trace-warnings and paste the full stack trace for the warning you are getting? That will help narrow down what is adding that event listener (at least, the 11th one). I am suspecting this is ultimately a Node.js issue, as there is nothing in your example script in Express.js that adds error event listeners. |
You can the error output below and I started my server using the
I have also tried the LTS version of Node.js which didn't really make a difference. This error only happens when using Express and not when using the built-in modules on their own. |
Hi @VeryHamburger so I was able to set up a server and use the site you gave and reproduce the warning you got, both with and without Express.js. It seems you were also able to reproduce the warning without Express.js in use as well, though. I looked into the warning, and it is all happening within Node.js itself, before Express.js can do anything. Unfortunately you likely will need to report this issue to Node.js. You're welcome to use the code I posted above for the report, which doesn't use Express.js at all, to help the Node.js project reproduce the issue 👍 |
I only get the warning with Express and not in Node.js itself. I thought it happened on both but my |
Hm, very strange.I was able to reproduce on both. But in Express.js code, nothinf is adding the error listener that is leaking with the warning. That event listener is being added by Node.js itself, before the request is ever even handed to Express.js. It is unclear how Express.js can fix the issue you have provided, as the code it all within the Node.js code base and not Express.js... |
What I have debugged so far in Node.js is that the case seems to be a flaw in the logic of that internal |
Hello,
Using the built-in
http
andhttps
packages causes a memory leak when the server gets flooded with requests from different IPs which eventually crashes the server.Code
Error
The text was updated successfully, but these errors were encountered: