You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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: