Domanda

On googling i found out this means too many files open but I have checked and there is none but this server running.Someone please help me out.

events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EMFILE
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1023:19)
at listen (net.js:1064:10)
at Server.listen (net.js:1138:5)
at Function.app.listen (/home/kkcorps/Desktop/check/node_modules/express/lib/application.js:529:24)
at Object. (/home/kkcorps/Desktop/check/port_2.js:48:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)

Here's my Code:

var express = require('express');
var path = require('path');

var app = express();

app.configure(function(){
    app.use(express.logger('dev'));
    app.use(express.bodyParser());
    app.use(express.cookieParser());
    app.use(express.static('static'));
    app.set('view engine', 'hbs');
    app.set('views', path.join(__dirname, 'views'));
});

var net = require('net');
var port = 1;
var timeout = 2000;
var open_ports = [];
while(port < 10000)
{
    (function(port){
    var sckt = new net.Socket();
    sckt.setTimeout(timeout, function(){
        sckt.destroy();
    });
    sckt.connect(port,function(){
        console.log('connected to localhost on port: '+ port);
        open_ports.push(port);
        //client.write('connected to localhost');
    });
    sckt.on('error',function(e){
        sckt.destroy();
    });
    })(port);

    port++;
}

//open_ports = ['1','2','3'];
app.get('/', function(req, res){
    //res.send('Hello world');
    res.render('index', {cont: open_ports});
})

app.listen(3000);
console.log('server running on port 3000');
È stato utile?

Soluzione

"too many files open" => "too many file descriptors open". Socket === file descriptor, so it's not surprising. You can try 2 things: tweak ulimit -n (on Unix-based system) or/and limit concurrency: opening 10000 sockets at once sounds like a bad idea. async.parallelLimit is one way to do that.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top