-
Notifications
You must be signed in to change notification settings - Fork 852
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
Too many subscriptions to Server.close event cause a OOM? #954
Comments
same issue. |
@LRagji thanks, saved me some time! :) |
Any updates on this? |
I got the same error when used a proxy in Parcel |
We're also getting this warning message, @LRagji, but the code you linked should add the on-close-event-listener only once as if (server && !this.serverOnCloseSubscribed) {
server.on('close', () => {
debug('server close signal received: closing proxy server');
this.proxy.close();
});
this.serverOnCloseSubscribed = true;
} Were you able to debug it? |
@rene-leanix If i remember this correctly, Its about adding the event handler every-time a request is made.. |
@LRagji, I just found out that in our code we're calling
But if you look at the code snippet above, I can't see how that could happen, if |
Again this was long back but i remember the |
I tried to reproduce it as described in your initial post by spinning up that simple app and executing more than 10 curl requests simultaneously against that endpoint, but all requests succeeded and now warning was logged. I also debugged the code you linked to and both the Could your load-testing setup have triggered a restart of the server between requests? @Jokero, @fetis, @khoale-groove or @f4z3k4s: can any of you confirm that this issue happens apart from |
@rene-leanix What version are you testing?, and if your don't mind can you share your code which was calling create method over and over again? I can see a lot of changes that happened for those specific method 'create proxy' in the library for different version |
@LRagji, I am using the latest versions for Regarding the code calling the API, I used the quick & dirty curl http://localhost:3000/api & curl http://localhost:3000/api & ... & curl http://localhost:3000/api with more than 10 curl statements. |
@rene-leanix We call it on application startup to configure and create proxies middleware, smth like this function proxyHelper() {
// our custom code and reconfiguration
return createProxyMiddleware();
}
app.use(proxyHelper()) |
Checks
http-proxy-middleware
.Describe the bug (be clear and concise)
This is a observation which is pointing out to a potential OOM, in our application we are using this package as shown in your first example.
and we are stress testing this API with multiple requests, it has been observed that following code is attaching multiple event handlers on the
server.close
, which prompts node to think its a memory leak.MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 connected listeners added to [NativeConnection].
The obvious way to fix this is to create the middleware once capture it in a variable and use that as shown in your 3rd example on the readme page instead of recreating the middleware every time as shown by the first example.
If our conclusion is right then i think you should remove inline creation of the middleware from your examples, so that other don't fall for the same issue.
Step-by-step reproduction instructions
Expected behavior (be clear and concise)
Should not see this warning in the console
MaxListenersExceededWarning: Possible EventEmitter memory leak detected
How is http-proxy-middleware used in your project?
What OS/version and node/version are you seeing the problem?
Additional context (optional)
No response
The text was updated successfully, but these errors were encountered: