Closed
Description
I'm testing a proxy on a separate java app. The app has about 280 static resources (js, css and images) in non-production mode.
After a number of requests on a single page load, I start getting the EMFILE error, which typically indicates a resource leak, more precisely "Too many open file descriptors".
Attached my code below.
- Would provide any pointers on what could be the problem?
- Do you have any recommendations on handling request and response objects to avoid leaks?
- Not sure if this is related, but can you explain why proxyReq.end() is commented out? Is it intentional?
code contains only the relevant parts:
init: function(proxyOptions) {
...
this.proxy = new httpProxy.createProxyServer(proxyOptions);
this.proxy.on('proxyRes', this.handleProxyResponse.bind(this));
this.server = http.createServer(this.handleWebRequest.bind(this));
this.server.listen(this.port);
},
handleWebRequest: function (req, res) {
this.emit('request', req, res);
this.proxy.web(req, res, this.proxyOptions);
},
handleProxyResponse: function (res) {
var req = res.req;
if (this.isHttpRedirect(res)) {
var reqUrl = (req.connection.encrypted ? 'https://' : 'http://') + req.getHeader('host'),
// need to use url.resolve() in case location is a relative URL
location = url.resolve(reqUrl, res.headers.location), //res.getHeader('location');
locationObj = url.parse(location);
this.rewriteLocation(locationObj, res);
}
this.emit('proxy-response', res);
},
Thanks,
Metadata
Metadata
Assignees
Labels
No labels