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

Too many subscriptions to Server.close event cause a OOM? #954

Open
2 tasks done
LRagji opened this issue Nov 27, 2023 · 4 comments
Open
2 tasks done

Too many subscriptions to Server.close event cause a OOM? #954

LRagji opened this issue Nov 27, 2023 · 4 comments

Comments

@LRagji
Copy link

LRagji commented Nov 27, 2023

Checks

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.

import * as express from 'express';
import { createProxyMiddleware, Filter, Options, RequestHandler } from 'http-proxy-middleware';

const app = express();

app.use('/api', createProxyMiddleware({ target: 'http://www.example.org', changeOrigin: true }));
app.listen(3000);

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

1. Create the example one as shown in the readme page. Node v18, Install latest of this package.
2. Make sure the upstream server takes 1 second to complete the request.
3. Nuke the api with any performance tool or stress test tool.

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?

As shown in example 1:


import * as express from 'express';
import { createProxyMiddleware, Filter, Options, RequestHandler } from 'http-proxy-middleware';

const app = express();

app.use('/api', createProxyMiddleware({ target: 'http://www.example.org', changeOrigin: true }));
app.listen(3000);


### What http-proxy-middleware configuration are you using?

```typescript
Default

What OS/version and node/version are you seeing the problem?

Node v18
OS: Node official container.

Additional context (optional)

No response

@khoale-groove
Copy link

same issue.

@f4z3k4s
Copy link

f4z3k4s commented Jan 30, 2024

@LRagji thanks, saved me some time! :)

@fetis
Copy link

fetis commented Apr 15, 2024

Any updates on this?

@Jokero
Copy link

Jokero commented Apr 30, 2024

I got the same error when used a proxy in Parcel

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

5 participants