Error: EMFILE: too many open files, watch, unless I use sudo

Error: EMFILE: too many open files, watch, unless I use sudo

描述

最近我 运行 遇到了一个问题。我无法在 element-web 目录中 运行 yarn start,我得到这些 errors. Originally I thought it had something to do with element-web itself so I created an issue. Some time after that I tried to run wintersmith preview in bibviz directory and got the same errors. This was weird so I tried to create an Angular project and run ng serve and errors again. I headed to the issue to close it as it wasn't an element-web issue. I found that there was another issue created with the same problem. It had already been closed by turt2liveit looks like you've run out of memory on your system。基于此,我尝试在后台关闭大多数程序 运行ning,现在所有命令都有效。

我确信 ng serve 过去曾经工作过。

我的 PC 有 16 GB 的 RAM,当我在 7/16 GB 时命令已经失败。 运行 执行命令时,我看不到任何内存峰值。 运行 带有 sudo 的命令也完全消除了问题。这对我来说没有任何意义。

研究将我引向 ulimits,但它们似乎没有效果。我也安装了 watchman 没有效果。

谁能告诉我我错过了什么?

提前致谢!

信息

我正在使用 Debian 11 Bullseye。这是一些可能有用的命令的输出。

作为普通用户:

> uname -a
Linux Simon-s-PC 5.8.0-3-amd64 #1 SMP Debian 5.8.14-1 (2020-10-10) x86_64 GNU/Linux
> sudo sysctl fs.inotify.max_user_watches
fs.inotify.max_user_watches = 524288
> ulimit -a
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-m: resident set size (kbytes)      unlimited
-u: processes                       46482
-n: file descriptors                8192
-l: locked-in-memory size (kbytes)  unlimited
-v: address space (kbytes)          unlimited
-x: file locks                      unlimited
-i: pending signals                 63664
-q: bytes in POSIX msg queues       819200
-e: max nice                        0
-r: max rt priority                 95
-N 15:                              unlimited
> yarn --version
1.22.5

sudo su:

> sysctl fs.inotify.max_user_watches
fs.inotify.max_user_watches = 524288
> ulimit -a
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-m: resident set size (kbytes)      unlimited
-u: processes                       63664
-n: file descriptors                1024
-l: locked-in-memory size (kbytes)  2043392
-v: address space (kbytes)          unlimited
-x: file locks                      unlimited
-i: pending signals                 63664
-q: bytes in POSIX msg queues       819200
-e: max nice                        0
-r: max rt priority                 0
-N 15:                              unlimited

我想我找到了解决办法:

  • /etc/sysctl.conf 中设置限制,方法是添加:
fs.inotify.max_user_watches=524288
fs.inotify.max_user_instances=512
  • 打开一个新终端或使用

    重新加载sysctl.conf个变量
    sudo sysctl --system
    
  • 运行 yarn start

希望现在一切正常。如果它不起作用,请尝试将限制设置得更高。