node and Error: EMFILE, too many open files

前端 未结 18 1785
终归单人心
终归单人心 2020-11-28 17:58

For some days I have searched for a working solution to an error

Error: EMFILE, too many open files

It seems that many people have the same proble

18条回答
  •  一向
    一向 (楼主)
    2020-11-28 18:33

    Building on @blak3r's answer, here's a bit of shorthand I use in case it helps other diagnose:

    If you're trying to debug a Node.js script that is running out of file descriptors here's a line to give you the output of lsof used by the node process in question:

    openFiles = child_process.execSync(`lsof -p ${process.pid}`);
    

    This will synchronously run lsof filtered by the current running Node.js process and return the results via buffer.

    Then use console.log(openFiles.toString()) to convert the buffer to a string and log the results.

提交回复
热议问题