我收到此错误:

Caught  signal; preparing to exit; please wait for 5 seconds
[TypeError: Cannot read property 'addListener' of undefined]
Caught  signal; preparing to exit; please wait for 5 seconds
{ [Error: spawn /bin/sh EMFILE]
  code: 'EMFILE',
  errno: 'EMFILE',
  syscall: 'spawn /bin/sh',
  path: '/bin/sh' }


在此代码之前,我正在获取日志。
实际上,Nodejs服务器收到了100个读取某些文件的请求。可能是什么问题呢?
我已经检查了最大进程限制,即kernel.pid_max =32768。它实际产生的进程少于2000个进程。我可以在我的帐户中看到open files限制为15000。

var path = null;
if (request.FileType & requestTypeEnum.LocalProgramFileOnly)
    {
        path = "../readfile  ";
    }
else
    {
        path = "../File-loggedin/readfile  ";
    }

var cmd = path +
        tmpobj.name +
        " recognize " +
        (request.isfirefox ? "1" : "0") +
        "  " + logobj.name + " " + resobj.name;
var exec = require('child_process').exec;
exec(cmd,
        function (error, stdout, stderr)
            {

                if (error !== null)
                    {

                        console.log(request.cid + "closing the connection");

                    }

                require("fs").readFile(resobj.name, 'utf8', function (err, data)
                    {

                        if (err)
                            {
                                throw err;
                            }

                        //Write into the database
                        store_request_db_success(request, 'File_Actual_LocalSoftware', null, db_params, data);
                        deduct_balance(request, FileCompanies.LocalSoftware);
                        var ret = getInitializedResponseData(request);
                        ret["decoded_File"] = {
                            File: data,
                            s_reqno: request.s_reqno
                        };
                        try
                            {
                                conn.sendText(JSON.stringify(ret));
                            }
                        catch (err)
                            {
                                console.log(request.cid, err);
                            }

                    });
            });


 ulimit -a

 core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 48033
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 15000
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 48033
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

最佳答案

确实有超过15000个打开文件描述符达到了极限。

发送响应时,我只是在tmpobj.removeCallback();之后添加了conn.sendText。然后在工作完成后关闭文件描述符。

tmpobj是使用tmp.fileSync创建的

10-05 20:15