Skip to content

Experiencing Error: connect EMFILE #585

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

Closed
simoami opened this issue Feb 19, 2014 · 1 comment
Closed

Experiencing Error: connect EMFILE #585

simoami opened this issue Feb 19, 2014 · 1 comment

Comments

@simoami
Copy link

simoami commented Feb 19, 2014

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.

  1. Would provide any pointers on what could be the problem?
  2. Do you have any recommendations on handling request and response objects to avoid leaks?
  3. 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,

@simoami
Copy link
Author

simoami commented Feb 19, 2014

Sorry, just realized this is the same as #570. Using http.globalAgent as default agent solves the problem. Closing this issue as duplicate.

@simoami simoami closed this as completed Feb 19, 2014
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

1 participant