2014-05-11 2 views
0

인터넷 검색에서 이것은 너무 많은 파일이 열렸다는 것을 알았지 만 검사했고 아무 것도 있지만이 서버는 실행되지 않았습니다. 누군가 나를 도와주세요.처리되지 않은 오류 nodejs 응용 프로그램의 EMFILE

events.js : 72
throw er; // 처리되지 않은 '오류'이벤트
^
오류 : 순 듣고에서
((: 904 : 11 net.js) Server._listen2에서
(19 net.js : 1023) EMFILE
errnoException에서 듣기 .js : 1064 : 10)
Server.listen (net.js : 1138 : 5)
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) Module.load (module.js에서
: 356 : 32) Function.Module._load (module.js에서
: 312 :

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'); 

답변

1

: 12)

여기

내 코드입니다 "너무 많은 파일을 열었습니다"=> "너무 많은 파일 설명자를 열었습니다." Socket === 파일 기술자이므로 놀라운 일이 아닙니다. 당신은 두 가지를 시도 할 수 있습니다 : ulimit -n (Unix 기반 시스템에서) 또는 동시성 제한 : 한 번에 10000 소켓 열기는 좋지 않은 생각처럼 들립니다. async.parallelLimit은이를 수행하는 한 가지 방법입니다.

+0

socket.connect에 로컬 호스트 IP (즉, 127.0.0.1)를 추가하는 방법을 모르지만 프로그램이 올바르게 실행되기 시작했습니다. – user3625371

+0

이상한가,'localhost'와 동일합니까? – vkurchatkin

관련 문제