Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
473 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...