Skip to content
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

possible EventEmitter memory leak detected. 11 upgrade listeners added. Use emitter.setMaxListeners() to increase limit. #108

Closed
wangduanduan opened this issue Sep 7, 2016 · 2 comments

Comments

@wangduanduan
Copy link

(node) warning: possible EventEmitter memory leak detected. 11 upgrade listeners added. Use emitter.setMaxListeners() to
increase limit.
Trace
at Server.addListener (events.js:239:17)
at catchUpgradeRequest (E:\work\saas\node_modules.npminstall\http-proxy-middleware\0.17.1\http-proxy-middleware\lib
\index.js:51:16)
at middleware (E:\work\saas\node_modules.npminstall\http-proxy-middleware\0.17.1\http-proxy-middleware\lib\index.js
:46:13)
at Layer.handle as handle_request
at trim_prefix (E:\work\saas\node_modules\express\lib\router\index.js:312:13)
at E:\work\saas\node_modules\express\lib\router\index.js:280:7
at Function.process_params (E:\work\saas\node_modules\express\lib\router\index.js:330:12)
at next (E:\work\saas\node_modules\express\lib\router\index.js:271:10)
at logger (E:\work\saas\node_modules\morgan\index.js:144:5)
at Layer.handle as handle_request

Expected behavior

Actual behavior

Setup

  • http-proxy-middleware: _version_0.17.1
  • server: connect/express/browser-sync... + version
  • other relevant modules

proxy middleware configuration

// filePath: /app.js
...
var sdkProxy = proxy('/mvc/stomp',{
    target       :sdk_target,
    changeOrigin :true,
    ws           :true,
    logLevel     :'info'
});
...
var app = express();
...
app.use(sdkProxy);
...
module.exports = app;


// filePath: /bin/www
var app   = require('../app');
...
var server = http.createServer(app);

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
...

i don't kown how to minitor the upgrade event

in your websocket example, everything just in one file。but in express project, it hava /app.js and /bin/www, i don't konw how to handler this.

looking forward to your reply.

@chimurai
Copy link
Owner

chimurai commented Sep 8, 2016

The code snippets doesn't seem to reveal the cause of the issue.

Somewhere you are constantly subscribing to an event, instead of subscribing it once.

Think StackOverflow is a better place to troubleshoot your project/setup.

Feel free to re-open the issue if you think the memory leak is caused by http-proxy-middleware. In that case, please provide a minimal working setup to help identifying the issue.

Thanks.

@burtontanner
Copy link

burtontanner commented Jun 29, 2023

This happened to me when I created the middleware on every single request. I saw this exact error and it was fixed by only creating the middleware once. Our servers would run out of memory in a few hours. Hope this helps.

thewilkybarkid added a commit to PREreview/prereview.org that referenced this issue Jun 12, 2024
When upgrading the http-proxy-middleware library I accidentally caused the app to create a new proxy server on every request (whether for the proxy or not), rather than just on startup. This led to a memory leak, and the Node process crashing.

This change creates it once, and uses the express-async-handler to get around triggering the no-misused-promises linting rule.

Refs #1636, chimurai/http-proxy-middleware#108 (comment), https://github.com/chimurai/http-proxy-middleware/tree/v3.0.0?tab=readme-ov-file#express-server-example, https://typescript-eslint.io/rules/no-misused-promises/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants