Skip to content

Error: connect EMFILE and node-http-proxy #567

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
stockholmux opened this issue Jan 29, 2014 · 5 comments
Closed

Error: connect EMFILE and node-http-proxy #567

stockholmux opened this issue Jan 29, 2014 · 5 comments

Comments

@stockholmux
Copy link

I'm trying to reverse proxy three localhost ports to a single localhost port. I keep getting the error:

{ [Error: connect EMFILE] code: 'EMFILE', errno: 'EMFILE', syscall: 'connect' }

After about ~100 serves. I can connect directly to the servers without issue for thousands of serves and nginx works well using the same reverse proxy.

Here is my code:

var http = require('http'),
    httpProxy = require('http-proxy');

var proxy = httpProxy.createProxyServer({});

var server = require('http').createServer(function(req, res) {
    if (req.url.match(/^(\/api\/search|\/api\/suggest)/g)) {
        proxy.web(req, res, { target: 'http://127.0.0.1:2700' });
    } else if (req.url.match(/^\/pages\//g)){
        proxy.web(req, res, { target: 'http://127.0.0.1:3100' });
    } else {
        proxy.web(req, res, { target: 'http://127.0.0.1:3000' });
    }
});

server.listen(9999);

I have also asked about the same issue in this Stackoverflow question. EMFILE issues seem to be around issues with maxfiles, but it given that I can run everything without the proxy with no issues, it seems like node-http-proxy not closing something?

@Rush
Copy link
Contributor

Rush commented Jan 29, 2014

I would suggest running node 0.11.10, there have been some fixes in the unstable branch regarding such problems. See also #488 and discussion regarding http agent. Personally I do not want the agent and I am running node 0.11 with good results.

@stockholmux
Copy link
Author

Interesting. I'm not sure unstable is an option for me at the moment. I'm running Node v0.10.25 (latest stable) and definitely has the issue described (as did the earlier version v0.10 that I upgraded from).

@jcrugzz
Copy link
Contributor

jcrugzz commented Jan 30, 2014

@stockholmux this probably has to do with your machine's ulimit which handles the number of file descriptors your computer will allow you to open. Make that infinity or a larger number and you should be fine. you can see how we set this for most of our production machines here

@jcrugzz
Copy link
Contributor

jcrugzz commented Jan 30, 2014

Closing as this is not an issue with http-proxy :).

@jcrugzz jcrugzz closed this as completed Jan 30, 2014
@martijnve
Copy link

Am I wrong in thinking there is a leak here? "-n The maximum number of open file descriptors. " implies to me that this is a limit on the amount of open handlers at one time. The fact that this limit can be breached with light usage makes me think http-proxy fails to close (some of) its handles correctly, and thus has an ever increasing number of open file descriptors. So while raising the limit will almost certainly solve the problem (at least temporarily) it seems like an ugly hack to me. What happens if traffic increases significantly, will the new limit be reached after a few months?

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

4 participants