events.js:48
throw arguments[1]; // Unhandled 'error' event
^
Error: connect EMFILE
at errnoException (net.js:670:11)
at connect (net.js:548:19)
at Socket.connect (net.js:613:5)
at Object.<anonymous> (/Users/zen/Documents/work/game.js:10:5)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Array.<anonymous> (module.js:484:10)
at EventEmitter._tickCallback (node.js:190:38)
在一个1000次的循环里构造并且连接到1234端口的socket报这个错误,这个错误是linux系统错误:“打开了过多文件”。
想问大家有遇到这个问题吗?
是不是和linux的任何都是文件的概念有关?
6 回复
我对linux的印象是任何IO都是管道,但是管道的API属于FILE。 nodejs关于流的api里和Socket的options里有个文件描述符fd。API中的描述是:
stream.write(string, [encoding], [fd])#
If the optional fd parameter is specified, it is interpreted as an integral file descriptor to be sent over the stream. This is only supported for UNIX streams, and is silently ignored otherwise. When writing a file descriptor in this manner, closing the descriptor before the stream drains risks sending an invalid (closed) FD.