3

Well, ignore it. I have opened an issue https://github.com/joyent/node/issues/793

Trying to run http://www.catonmat.net/http-proxy-in-nodejs

var http = require('http');

http.createServer(function(request, response) {
  var proxy = http.createClient(80, request.headers['host'])
  var proxy_request = proxy.request(request.method, request.url, request.headers);
  proxy_request.addListener('response', function (proxy_response) {
    proxy_response.addListener('data', function(chunk) {
      response.write(chunk, 'binary');
    });
    proxy_response.addListener('end', function() {
      response.end();
    });
    response.writeHead(proxy_response.statusCode, proxy_response.headers);
  });
  request.addListener('data', function(chunk) {
    proxy_request.write(chunk, 'binary');
  });
  request.addListener('end', function() {
    proxy_request.end();
  });
}).listen(8080);

Fails after a huge number of requests with:

net.js:695
        self.fd = socket(self.type);
                  ^
Error: EMFILE, Too many open files
    at net.js:695:19
    at dns.js:171:30
    at IOWatcher.callback (dns.js:53:15)

node 0.4.2 on OSX 10.6

  • what version of node are you using, there has been many patches since 1.3 (where I believe this error started) – RobertPitt Mar 16 '11 at 10:36

2 Answers2

8

You may be hitting your (default) maximum value of opened files in your operating system (for Linux it's 1024), especially if your are doing huge number of requests. For example in Linux you can increase this resource limit with ulimit command:

ulimit -n 8192
yojimbo87
  • 65,684
  • 25
  • 123
  • 131
  • 1
    what does mean `8192` –  May 23 '15 at 08:21
  • it doesn't mean anything. It is only a number which defined by yourself by your needs. Actually 8192 is 8 times of 1024. If you receive too much nodejs websocket connection (for example 100K), then you need to increase this number to 1024*100*2 = 204800 at least. – kodmanyagha May 21 '22 at 07:07
3

Resurrecting an old post here but I wanted to add my own answer for Ubuntu (couldn't get the ulimit command working :s ):

$ sudo vim  /etc/security/limits.conf

Add the following:

SOME_USER hard nofile SOME_NUMBER
SOME_USER soft nofile SOME_NUMBER

Replace SOME_USER with your user. Replace SOME_NUMBER with a number higher than the limit that is causing problems.

$ sudo vim /etc/pam.d/common-session

Add the following:

session required pam_limits.so

Reboot your machine and the problem should be fixed :).

ale
  • 11,636
  • 27
  • 92
  • 149