TypeError:无法读取属性' addListener'未定义错误:spawn / bin / sh EMFILE

时间:2017-08-29 14:42:34

标签: node.js

我收到此错误:

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

1 个答案:

答案 0 :(得分:0)

实际上超过15000个打开文件描述符触及了极限。

我刚刚在tmpobj.removeCallback();发送回复后添加了conn.sendText。然后在工作完成时关闭文件描述符。

tmpobj是使用tmp.fileSync

创建的